In some tests, I saw that using prototypes improves code execution performance and reduces memory consumption, since methods are created for each class, and not for each object. At the same time, I want to use the module template for my class, because it looks better and allows you to use private properties and methods.
The code diagram is as follows:
var MyClass = function() {
var _classProperty = "value1";
var object = {
classProperty : _classProperty
};
object.prototype = {
prototypeProperty = "value2"
}
return object;
}
But the prototype in this case does not work. I found that the reason is that prototypes are set for functions, not for the object. Therefore, I suggest that object.prototypeI should use instead object.__proto__.prototype. But it is __proto__not supported by all browsers and does not comply with ECMAScript5 rules.
, ?