Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

How object.create() is different then usual js object creation?

user-image
Question ajoutée par irfan shaikh , Consultant : Senior Web Designer/Front end Developer , Client : ● Impact Proximity, Dubai ● Cube Solution, Dubai ● WAC, Sharjha ● KIOEC, Kuwait ● IRIS Ltd.
Date de publication: 2013/10/21
Adeem Salik
par Adeem Salik , Sr Software Engineer , Emirates Auction

with Create a new object with the specified prototype object and properties can be created

 

with object.create() you can initialize the object with your own default value (scripted in the create function) while in new object() properties cannot be set while creating instance and you have to set properties later. See examples below:

 

Creating a Direct Instance:

 

person=new Object();

person.firstname="John";

person.lastname="Doe";

person.age=50;

person.eyecolor="blue";

 

 

Using an create Constructor:

 

function create(firstname,lastname,age,eyecolor)

{

this.firstname=firstname;

this.lastname=lastname;

this.age=age;

this.eyecolor=eyecolor;

}

 

More Questions Like This

Avez-vous besoin d'aide pour créer un CV ayant les mots-clés recherchés par les employeurs?