Original Type inheritance

Source: Internet
Author: User

Function object (o ){

Function f (){}
F. Prototype = O;
Return new F ();
}

// You can create a new object based on an existing object by using the prototype without having to create a custom type for Chu,

// Within the object function, a temporary constructor is created, the input object is used as the prototype of the constructor, and the temporary type of constructor is returned.
// New instance. In essence, an object () performs a previous copy of the object in it.

VaR person = {
Name: "Nicolas ",
Friends: ["Shelby", "Count", "Wan"]
};

VaR anotherperson = Object (person );
Anotherperson. Name = "Greg ";
Anotherperson. Friends. Push ("Rob ");

VaR anotherperson2 = Object (person );
Anotherperson2.name = "greg2 ";
Anotherperson2.friends. Push ("rob2 ");

Console. Log (anotherperson2.friends );

 

// Inherit object. Create () to normalize the prototype ();

// When a parameter is input, it is the same as the object function.

VaR person = {
Name: "shalio ",
Friends: ["hahs", "Jk", "ll"]
};

VaR anotherperson = object. Create (person );

// You can also input two parameters for this method, which are similar to object. defineproperties.

VaR newperson = object. Create (person, {Name: {value: "hhhh "}});

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.