--- id: 587d7dad367417b2b2512b78 title: Use a Constructor to Create Objects challengeType: 1 videoUrl: '' localeTitle: استخدم منشئ لإنشاء كائنات --- ## Description
هنا منشئ Bird من التحدي السابق:
وظيفة الطيور () {
this.name = "Albert"؛
this.color = "blue"؛
this.numLegs = 2 ،
// "هذا" داخل المنشئ يشير دائمًا إلى الكائن الذي يتم إنشاؤه
}

واسمحوا blueBird = الطيور الجديدة () ؛
لاحظ أن المشغل new يستخدم عند استدعاء منشئ. هذا يخبر JavaScript لإنشاء instance جديد من Bird باسم blueBird . بدون المشغل new ، لا يشير this داخل المُنشئ إلى الكائن الذي تم إنشاؤه حديثًا ، مما يعطي نتائج غير متوقعة. الآن blueBird لديه كل الخصائص التي تم تعريفها داخل منشئ Bird :
blueBird.name. // => ألبرت
blueBird.color. // => أزرق
blueBird.numLegs. // => 2
تمامًا مثل أي كائن آخر ، يمكن الوصول إلى خصائصه وتعديلها:
blueBird.name = 'Elvira' ،
blueBird.name. // => إلفيرا
## Instructions undefined ## Tests
```yml tests: - text: يجب إنشاء hound باستخدام منشئ Dog . testString: 'assert(hound instanceof Dog, "hound should be created using the Dog constructor.");' - text: يجب أن تستخدم شفرتك المشغل new لإنشاء instance Dog . testString: 'assert(code.match(/new/g), "Your code should use the new operator to create an instance of Dog.");' ```
## Challenge Seed
```js function Dog() { this.name = "Rupert"; this.color = "brown"; this.numLegs = 4; } // Add your code below this line ```
## Solution
```js // solution required ```