fix(challenge): Format constructor property in "OOP: Set Constructor"
parent
22d612dd84
commit
ee6c544009
|
@ -507,12 +507,12 @@
|
||||||
"id": "587d7daf367417b2b2512b80",
|
"id": "587d7daf367417b2b2512b80",
|
||||||
"title": "Remember to Set the Constructor Property when Changing the Prototype",
|
"title": "Remember to Set the Constructor Property when Changing the Prototype",
|
||||||
"description": [
|
"description": [
|
||||||
"There is one crucial side effect of manually setting the <code>prototype</code> to a new object. It erased the constructor property! The code in the previous challenge would print the following for <code>duck</code>:",
|
"There is one crucial side effect of manually setting the <code>prototype</code> to a new object. It erased the <code>constructor</code> property! The code in the previous challenge would print the following for <code>duck</code>:",
|
||||||
"<blockquote>console.log(duck.constructor)<br>// prints ‘undefined’ - Oops!</blockquote>",
|
"<blockquote>console.log(duck.constructor)<br>// prints ‘undefined’ - Oops!</blockquote>",
|
||||||
"To fix this, whenever a prototype is manually set to a new object, remember to define the constructor property:",
|
"To fix this, whenever a prototype is manually set to a new object, remember to define the <code>constructor</code> property:",
|
||||||
"<blockquote>Bird.prototype = {<br> constructor: Bird, // define the constructor property<br> numLegs: 2,<br> eat: function() {<br> console.log(\"nom nom nom\");<br> },<br> describe: function() {<br> console.log(\"My name is \" + this.name); <br> }<br>};</blockquote>",
|
"<blockquote>Bird.prototype = {<br> constructor: Bird, // define the constructor property<br> numLegs: 2,<br> eat: function() {<br> console.log(\"nom nom nom\");<br> },<br> describe: function() {<br> console.log(\"My name is \" + this.name); <br> }<br>};</blockquote>",
|
||||||
"<hr>",
|
"<hr>",
|
||||||
"Define the constructor property on the <code>Dog</code> <code>prototype</code>."
|
"Define the <code>constructor</code> property on the <code>Dog</code> <code>prototype</code>."
|
||||||
],
|
],
|
||||||
"challengeSeed": [
|
"challengeSeed": [
|
||||||
"function Dog(name) {",
|
"function Dog(name) {",
|
||||||
|
|
Loading…
Reference in New Issue