The attribute method in JS's function 4

Source: Internet
Author: User

Private method: The private method itself is accessible to all properties within the class, that is, the private property and the public property. However, private methods cannot be called outside the class.

Public method:

1. Public methods can be called outside of the class,

2. However, it does not have access to the private properties of the class.

3. The public method must be added inside or outside the class through the prototype property of the class.

Privileged methods:

1. Privileged methods can be called outside of the class,

2. However, it can access the private properties of the class, and it can also access the public properties of the class, and can reluctantly consider it to be a special public method.

3. However, it differs from the declaration and definition of the public method above. The privileged method must declare the definition within the class.

A "Private variable" is declared inside an object using the ' var ' keyword, and it can only be accessed by private functions and privileged methods.
"Private method" is declared in the object's constructor (or through Varfunctionname=function () {...} To define),
It can be called by privileged methods (including object construction methods) and private method calls, and private functions can only access private methods and properties.
"Privileged Method" through This.methodname=function () {...} To declare and possibly be called by code outside the object.
It can use the: this privilege function () method to invoke the privileged function, using the: Private Function () method to invoke the private function.

Public properties are defined by This.variablename and can be read and written outside of the object. cannot be called by a private function.
"Public method" through Classname.prototype.methodname=function () {...} To define can be called from outside the object.
The "prototype attribute" is defined by Classname.prototype.propertyname=somevalue.
Static properties are defined by Classname.propertyname=somevalue.
The static method is defined by the classname.funname=function () {...}.

Static method properties can only be called by the class itself

The attribute method in JS's function 4

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.