* fix: Chinese test suite Add localeTiltes, descriptions, and adjust test text and testStrings to get the automated test suite working. * fix: ran script, updated testStrings and solutions
2.1 KiB
2.1 KiB
id, title, challengeType, videoUrl, localeTitle
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
587d7db1367417b2b2512b86 | Reset an Inherited Constructor Property | 1 | 重置继承的构造函数属性 |
Description
prototype
,它也继承了supertype
的构造函数属性。这是一个例子: 函数Bird(){}但
Bird.prototype = Object.create(Animal.prototype);
let duck = new Bird();
duck.constructor // function Animal(){...}
duck
和所有Bird
实例都应该表明它们是由Bird
而不是Animal
建造的。为此,您可以手动将Bird's
构造函数属性设置为Bird
对象: Bird.prototype.constructor = Bird;
duck.constructor // function Bird(){...}
Instructions
duck.constructor
和beagle.constructor
返回各自的构造函数。 Tests
tests:
- text: <code>Bird.prototype</code>应该是<code>Animal</code>一个实例。
testString: assert(Animal.prototype.isPrototypeOf(Bird.prototype));
- text: <code>duck.constructor</code>应该返回<code>Bird</code> 。
testString: assert(duck.constructor === Bird);
- text: <code>Dog.prototype</code>应该是<code>Animal</code>一个实例。
testString: assert(Animal.prototype.isPrototypeOf(Dog.prototype));
- text: <code>beagle.constructor</code>应该返回<code>Dog</code> 。
testString: assert(beagle.constructor === Dog);
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