This article describes the usage of public, private, privileged, and static membership in JavaScript. Share it for your reference. The specific analysis is as follows:
The following content was excerpted from "Advanced Programming". It is easier to understand. I will record it here to facilitate the sharing of friends who are getting started with Javascript.
function myContructor(message){
= message;
//Private Attributes
var separator = ' -';
var myOwner = this;
//Private method
function alertMessage(){
alert();
}
alertMessage();
//Private method (also public method)
= function(string){
+= separator + string;
alertMessage();
}
}
//Public Method
= function(string){
= '';
}
// Static properties
= 'Jankerli';
// Static method
= function(){
alert();
}
Several rules regarding public, private, privileged, and static members:
1. Since private members and privileged members are inside the function, they will be brought to each instance of the function (that is, each instance created by the constructor will contain a copy of the same private and privileged members, so the more instances the more memory it consumes).
2. Public prototype members are part of the object blueprint and are suitable for each instance of the object instantiated through the new keyword.
3. Static members are only applicable to one special instance of the object (this special instance is the constructor itself as the instance of the Function object).
I hope this article will be helpful to everyone's JavaScript programming.