Several approaches to object-oriented (later) "Unfinished edition"

Source: Internet
Author: User

The way the literal is created using the constructor property does not point to the instance, but to the Object, the constructor creates
In the opposite way.

function Box () {}
Create the prototype object in the literal way, where {} is the object, and the Object,new object is the equivalent of {}
box.prototype={
Constructor:box,//force point to Box
Name: ' Lee ',
AGE:100,
Run:function () {
Return this.name+this.age+ "in operation ...";
}
};

Overridden a prototype object
box.prototype={
AGE:200//This will not retain any information from the previous prototype, the original prototype object and the constructor object instance before the relationship was cut off
};
var box=new box ();
alert (box.name);
alert (Box.constructor==box); True

Prototype schema creation object also has its own shortcomings, it omitted the constructor parameter initialization of the process, resulting in the lack of
The point is that the initialized values are consistent. And the biggest drawback of the prototype is its greatest advantage, that is sharing.

Four.

Several approaches to object-oriented (later) "Unfinished edition"

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.