freeCodeCamp/curriculum/challenges/arabic/02-javascript-algorithms-an.../object-oriented-programming/reset-an-inherited-construc...

2.7 KiB

id title challengeType videoUrl localeTitle
587d7db1367417b2b2512b86 Reset an Inherited Constructor Property 1 إعادة تعيين منشئ Conherrated الخاصية

Description

عندما يرث كائن prototype الخاص به من كائن آخر ، فإنه يرث أيضًا خاصية مُنشئ supertype . إليك مثال على ذلك:
وظيفة الطيور () {}
Bird.prototype = Object.create (Animal.prototype)؛
السماح بطة = الطيور الجديدة () ؛
duck.constructor // وظيفة الحيوان () {...}
ولكن يجب أن تظهر duck وجميع حالات Bird التي شيدت من قبل Bird وليس Animal . للقيام بذلك، يمكنك تعيين يدويا Bird's الملكية منشئ إلى Bird وجوه:
Bird.prototype.constructor = Bird؛
duck.constructor // function Bird () {...}

Instructions

إصلاح التعليمات البرمجية بحيث duck.constructor و beagle.constructor إرجاع beagle.constructor الخاصة بهم.

Tests

tests:
  - text: يجب أن يكون <code>Bird.prototype</code> مثالًا <code>Animal</code> .
    testString: 'assert(Animal.prototype.isPrototypeOf(Bird.prototype), "<code>Bird.prototype</code> should be an instance of <code>Animal</code>.");'
  - text: يجب أن يعود <code>duck.constructor</code> <code>Bird</code> .
    testString: 'assert(duck.constructor === Bird, "<code>duck.constructor</code> should return <code>Bird</code>.");'
  - text: يجب أن يكون <code>Dog.prototype</code> مثالا <code>Animal</code> .
    testString: 'assert(Animal.prototype.isPrototypeOf(Dog.prototype), "<code>Dog.prototype</code> should be an instance of <code>Animal</code>.");'
  - text: يجب أن يعود <code>beagle.constructor</code> <code>Dog</code> .
    testString: 'assert(beagle.constructor === Dog, "<code>beagle.constructor</code> should return <code>Dog</code>.");'

Challenge Seed

function Animal() { }
function Bird() { }
function Dog() { }

Bird.prototype = Object.create(Animal.prototype);
Dog.prototype = Object.create(Animal.prototype);

// Add your code below this line



let duck = new Bird();
let beagle = new Dog();

Solution

// solution required