Fix challenge title formatting misc

This commit is contained in:
dhcodes
2017-02-23 11:42:29 -06:00
parent f8da35f794
commit baf1d0cff8
24 changed files with 220 additions and 220 deletions

View File

@@ -123,14 +123,14 @@
},
{
"id": "587d7dad367417b2b2512b76",
"title": "Make Code More Reusable with This",
"title": "Make Code More Reusable with the this Keyword",
"description": [
"The last challenge introduced a <code>method</code> to the <code>duck</code> object. It used <code>duck.name</code> dot notation to access the value for the <code>name</code> property within the return statement:",
"<code>sayName: function() {return \"The name of this duck is \" + duck.name + \".\";}</code>",
"While this is a valid way to access the object's property, there is a pitfall here. If the variable name changes, any code referencing the original name would need to be updated as well. In a short object definition, it isn't a problem, but if an object has many references to its properties there is a greater chance for error.",
"A way to avoid these issues is with the <code>this</code> keyword:",
"<blockquote>let duck = {<br>&nbsp;&nbsp;name: \"Aflac\",<br>&nbsp;&nbsp;numLegs: 2,<br>&nbsp;&nbsp;sayName: function() {return \"The name of this duck is \" + this.name + \".\";}<br>};</blockquote>",
"<code>This</code> is a deep topic, and the above example is only one way to use it. In the current context, <code>this</code> refers to the object that the method is associated with: <code>duck</code>.",
"<code>this</code> is a deep topic, and the above example is only one way to use it. In the current context, <code>this</code> refers to the object that the method is associated with: <code>duck</code>.",
"If the object's name is changed to <code>mallard</code>, it is not necessary to find all the references to <code>duck</code> in the code. It makes the code reusable and easier to read.",
"<hr>",
"Modify the <code>dog.sayLegs</code> method to remove any references to <code>dog</code>. Use the <code>duck</code> example for guidance."