Public, private, privileged, and static member usage analysis _javascript techniques in JavaScript

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.