ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

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

user-image
تم إضافة السؤال من قبل irfan shaikh , Consultant : Senior Web Designer/Front end Developer , Client : ● Impact Proximity, Dubai ● Cube Solution, Dubai ● WAC, Sharjha ● KIOEC, Kuwait ● IRIS Ltd.
تاريخ النشر: 2013/10/21
Adeem Salik
من قبل 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;

}

 

المزيد من الأسئلة المماثلة