The following content is in the "Javascript.dom Advanced Program Design" excerpt out of it, I think it is easy to understand, afraid of later will forget or confused, especially in this record, but also with you are getting started JavaScript friends to share ah.
code is as follows |
copy code |
//constructor function mycontructor (message) { This.mymessage = message; / /private Property var separator = '-'; var myowner = this; //Private method Function Alertmessage () { Alert (myowner.mymessag e); } Alertmessage (); //Privileged Method (also public method) This.appendtomessage = function (string) { This.mymessage = Separator + string; Alertmessage (); } } //public method MyContructor.prototype.clearMessage = function (string) { This.mymessage = '; } //static properties Mycontructor.name = ' Jankerli '; //static method Mycontructor.alertname = function () { Alert (this.name ); } |
About public, several rules for private, privileged, and static members:
1, because private members and privileged members are inside the function, they are taken to each instance of the function (that is, each instance created by the constructor contains a copy of the same private and privileged member). As a result, more instances consume more memory.
2, a publicly-owned stereotype member is part of the object's blueprint and applies to each instance of the object instantiated with the New keyword.
3, static members apply only to a particular instance of an object (this particular instance is the constructor itself as a function object instance).