Yes, spot basically. The only thing you need to add is that you must prototype methods . As you prototype the situation in design, I usually prefer to do it inside the class, but it is labeled so that it runs only when necessary, and only once.
NAMESPACE.Person = function() { this.name = ""; this.gender = ""; this.age = 0; if(!NAMESPACE.Person._prototyped) { NAMESPACE.Person.prototype.MethodA = function () {}; NAMESPACE.Person.prototype.MethodB = function () {}; NAMESPACE.Person.prototype.MethodC = function () {}; NAMESPACE.Person._prototyped = true; } }
Explaining why: the reason for this is performance and inheritance. Prototyped properties are directly related to the object of the class (function), and not to the instance, therefore they are available only for reference to the function. And since they are in the class, only one object must exist, not one instance.
source share