The examples in this article describe the public, private, privileged, and static member usages in JavaScript. Share to everyone for your reference. The specific analysis is as follows:
The following content is in the "Javascript.dom Advanced Program Design" Inside excerpt out, relatively easy to understand, especially in this record, easy to get started JavaScript friends to share ah.
Copy Code code as follows:
Constructors
function Mycontructor (message) {
this.mymessage = message;
Private property
var separator = '-';
var myowner = this;
Private method
function Alertmessage () {
alert (myowner.mymessage);
}
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);
}
Several rules about public, 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 copies of the same private and privileged members, so the more instances consume more memory).
2. The public archetype member is part of the object blueprint, and applies to each instance of the object instantiated through 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).
I hope this article will help you with your JavaScript programming.