--- id: 587d7db1367417b2b2512b87 title: Add Methods After Inheritance challengeType: 1 videoUrl: '' localeTitle: إضافة طرق بعد الوراثة --- ## Description
لا تزال دالة منشئ ترث كائن نموذجها prototype من دالة منشئ supertype قادرة على استخدام أساليبها الخاصة بالإضافة إلى الأساليب الموروثة. على سبيل المثال ، Bird هو مُنشئ يرث prototype من Animal :
وظيفة الحيوان () {}
Animal.prototype.eat = function () {
console.log ("nom nom nom")؛

وظيفة الطيور () {}
Bird.prototype = Object.create (Animal.prototype)؛
Bird.prototype.constructor = Bird؛
بالإضافة إلى ما هو موروث من Animal ، فأنت تريد إضافة سلوك فريد لكائنات Bird . هنا ، سوف تحصل Bird على وظيفة fly() . يتم إضافة وظائف إلى Bird's prototype بنفس الطريقة مثل أي وظيفة المنشئ:
Bird.prototype.fly = function () {
console.log ("أنا أطير!") ؛
الآن سوف يكون لديك Bird من Bird على كلا أساليب eat() و fly() :
السماح بطة = الطيور الجديدة () ؛
duck.eat ()؛ // prints "nom nom nom"
duck.fly ()؛ // prints "أنا أطير!"
## Instructions
إضافة كافة التعليمات البرمجية الضرورية لذلك Dog يرث الكائن من Animal و Dog's prototype يتم تعيين المنشئ إلى الكلب. ثم أضف طريقة bark() إلى جسم Dog حتى يستطيع beagle أن eat() bark() . يجب أن تطبع طريقة bark() "Woof!" إلى وحدة التحكم.
## Tests
```yml tests: - text: لا ينبغي أن يستجيب Animal لطريقة bark() . testString: 'assert(typeof Animal.prototype.bark == "undefined", "Animal should not respond to the bark() method.");' - text: يجب أن يرث Dog طريقة eat() من Animal . testString: 'assert(typeof Dog.prototype.eat == "function", "Dog should inherit the eat() method from Animal.");' - text: يجب أن يكون Dog أسلوب bark() كخاصية own . testString: 'assert(Dog.prototype.hasOwnProperty("bark"), "Dog should have the bark() method as an own property.");' - text: beagle يجب أن يكون instanceof Animal . testString: 'assert(beagle instanceof Animal, "beagle should be an instanceof Animal.");' - text: يجب تعيين منشئ beagle Dog . testString: 'assert(beagle.constructor === Dog, "The constructor for beagle should be set to Dog.");' ```
## Challenge Seed
```js function Animal() { } Animal.prototype.eat = function() { console.log("nom nom nom"); }; function Dog() { } // Add your code below this line // Add your code above this line let beagle = new Dog(); beagle.eat(); // Should print "nom nom nom" beagle.bark(); // Should print "Woof!" ```
## Solution
```js // solution required ```