Skip to content

Commit 81c092e

Browse files
committed
Fix question 11
1 parent 687db7d commit 81c092e

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,9 @@ function Person(firstName, lastName) {
335335
}
336336

337337
const member = new Person("Lydia", "Hallie");
338-
Person.getFullName = () => this.firstName + this.lastName;
338+
Person.getFullName = function() {
339+
return this.firstName + " " + this.lastName;
340+
};
339341

340342
console.log(member.getFullName());
341343
```
@@ -352,9 +354,13 @@ console.log(member.getFullName());
352354

353355
You can't add properties to a constructor like you can with regular objects. If you want to add a feature to all object at once, you have to use the prototype instead. So in this case,
354356

355-
`Person.prototype.getFullName = () => this.firstName + this.lastName`
357+
```javascript
358+
Person.prototype.getFullName = function() {
359+
return this.firstName + " " + this.lastName;
360+
};
361+
```
356362

357-
would have made `lydia.getFullName()` work. Why is this beneficial? Say that we added this method to the constructor itself. Maybe not every `Person` instance needed this method. This would waste a lot of memory space, since they would still have that property, which takes of memory space for each instance. Instead, if we only add it to the prototype, we just have it at one spot in memory, yet they all have access to it!
363+
would have made `member.getFullName()` work. Why is this beneficial? Say that we added this method to the constructor itself. Maybe not every `Person` instance needed this method. This would waste a lot of memory space, since they would still have that property, which takes of memory space for each instance. Instead, if we only add it to the prototype, we just have it at one spot in memory, yet they all have access to it!
358364

359365
</p>
360366
</details>

0 commit comments

Comments
 (0)