* feat(tools): add seed/solution restore script * chore(curriculum): remove empty sections' markers * chore(curriculum): add seed + solution to Chinese * chore: remove old formatter * fix: update getChallenges parse translated challenges separately, without reference to the source * chore(curriculum): add dashedName to English * chore(curriculum): add dashedName to Chinese * refactor: remove unused challenge property 'name' * fix: relax dashedName requirement * fix: stray tag Remove stray `pre` tag from challenge file. Signed-off-by: nhcarrigan <nhcarrigan@gmail.com> Co-authored-by: nhcarrigan <nhcarrigan@gmail.com>
1.9 KiB
1.9 KiB
id, title, challengeType, forumTopicId, dashedName
id | title | challengeType | forumTopicId | dashedName |
---|---|---|---|---|
587d7db1367417b2b2512b86 | Reset an Inherited Constructor Property | 1 | 301324 | reset-an-inherited-constructor-property |
--description--
When an object inherits its prototype
from another object, it also inherits the supertype's constructor property.
Here's an example:
function Bird() { }
Bird.prototype = Object.create(Animal.prototype);
let duck = new Bird();
duck.constructor // function Animal(){...}
But duck
and all instances of Bird
should show that they were constructed by Bird
and not Animal
. To do so, you can manually set Bird's
constructor property to the Bird
object:
Bird.prototype.constructor = Bird;
duck.constructor // function Bird(){...}
--instructions--
Fix the code so duck.constructor
and beagle.constructor
return their respective constructors.
--hints--
Bird.prototype
should be an instance of Animal
.
assert(Animal.prototype.isPrototypeOf(Bird.prototype));
duck.constructor
should return Bird
.
assert(duck.constructor === Bird);
Dog.prototype
should be an instance of Animal
.
assert(Animal.prototype.isPrototypeOf(Dog.prototype));
beagle.constructor
should return Dog
.
assert(beagle.constructor === Dog);
--seed--
--seed-contents--
function Animal() { }
function Bird() { }
function Dog() { }
Bird.prototype = Object.create(Animal.prototype);
Dog.prototype = Object.create(Animal.prototype);
// Only change code below this line
let duck = new Bird();
let beagle = new Dog();
--solutions--
function Animal() { }
function Bird() { }
function Dog() { }
Bird.prototype = Object.create(Animal.prototype);
Dog.prototype = Object.create(Animal.prototype);
Dog.prototype.constructor = Dog;
Bird.prototype.constructor = Bird;
let duck = new Bird();
let beagle = new Dog();