JavaScript Object Properties and methods 4 different types _js Object oriented

Source: Internet
Author: User
The first type is the previously mentioned private type, which is characterized by a complete lack of access to the outside world to access them, only through specific getter and setter.
The second type is a dynamic public type, characterized by external access, and each instance of the object holds a copy that does not affect each other.
The third type is a static public type, or is often called a prototype attribute, which is characterized by the sharing of a unique replica for each object instance, and its rewriting affects each other.
The fourth type is the Class property, which is characterized as a property of the type and not an object instance, and can be accessed without constructing the object, and the following examples illustrate the characteristics and differences of the four attribute types:
Four attributes of a type
Copy Code code as follows:

<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<title>example 21.3</title>
<body>
&LT;H1 id= "Output" ><script language= "javascript" type= "Text/javascript" >
<!--
function Dwn (s)
{
document.write (S + "<br/>");
}
function MyClass ()
{
var p = 100; private property; Private property
This.x = 10; Dynamic Public Property
}
Myclass.prototype.y = 20; Static or prototype property prototype properties
Myclass.z = 30; static property//static properties
var a = new MyClass ();
Dwn (A.P); Undefined private Property object cannot be accessed to
Dwn (a.x); 10 Public properties
Dwn (A.Y); 20 Public properties
a.x = 20;
A.Y = 40;
Dwn (a.x); 20
Dwn (A.Y); 40//Dynamic Public property Y overrides the prototype attribute y
Delete (a.x);
Delete (A.Y);
Dwn (a.x); Undefined dynamic Public Property x does not exist after it has been deleted
Dwn (A.Y); 20 Dynamic public properties Y is deleted and revert to prototype property y
Dwn (A.Z); Undefined class properties cannot be accessed through an object
Dwn (MYCLASS.Z); Class 30 attributes should be accessed through the class
-->
</script>
</body>
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.