Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

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

user-image
Question added by irfan shaikh , Consultant : Senior Web Designer/Front end Developer , Client : ● Impact Proximity, Dubai ● Cube Solution, Dubai ● WAC, Sharjha ● KIOEC, Kuwait ● IRIS Ltd.
Date Posted: 2013/10/21
Adeem Salik
by Adeem Salik , Software Team Lead , khushhalibank

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

Do you need help in adding the right keywords to your CV? Let our CV writing experts help you.