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 () {...}
duck.constructor
و beagle.constructor
إرجاع beagle.constructor
الخاصة بهم. Bird.prototype
مثالًا Animal
.
testString: 'assert(Animal.prototype.isPrototypeOf(Bird.prototype), "Bird.prototype
should be an instance of Animal
.");'
- text: يجب أن يعود duck.constructor
Bird
.
testString: 'assert(duck.constructor === Bird, "duck.constructor
should return Bird
.");'
- text: يجب أن يكون Dog.prototype
مثالا Animal
.
testString: 'assert(Animal.prototype.isPrototypeOf(Dog.prototype), "Dog.prototype
should be an instance of Animal
.");'
- text: يجب أن يعود beagle.constructor
Dog
.
testString: 'assert(beagle.constructor === Dog, "beagle.constructor
should return Dog
.");'
```