So, the first question here is - be careful.
I am working on a rather difficult JavaScript project with several other developers from different background programs other than web programming, and we decided to try and use public and private methods and properties in our JavaScript classes only as good (i.e. we know that there is no actual advantage or security)
We played with several different ways of public and private (for example, using variables and functions with local scope with privileged methods for public consumption), and now we decided that our JavaScript class constructors actually return an object that represents only their public interface effectively hiding everything else.
Here is an example:
function MyObject()
{
var _this = this;
this._privateProperty = 'somevalue';
this._privateMethod = function()
{
}
this.public =
{
publicProperty : _this._privateProperty,
publicMethod : function(){ return _this.privateMethod() }
}
return this.public;
}
What when creating and registering in Chrome:
var obj = new MyObject();
console.log(obj);
Outputs:
> Object
> publicMethod: function (){ return _this.privateMethod() }
> publicProperty: "somevalue"
>__proto__: Object
Now to my question: Because you returned the public interface from the constructor as a new object, when you console.log you will notice that it identifies itself as > Object, whereas if we do not return this open interface, it will be identified as > MyObject.
, , , "MyObject" _this.constructor.name, , , .
- , ?
:
, - JavaScript , , , . , , , .