Skip to content

Commit 98a3362

Browse files
committed
Update "Object methods" files
1 parent 752e6ad commit 98a3362

File tree

3 files changed

+6
-9
lines changed

3 files changed

+6
-9
lines changed

1-js/04-object-basics/04-object-methods/4-object-property-this/solution.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ let user = makeUser();
1414
alert( user.ref.name ); // Error: Cannot read property 'name' of undefined
1515
```
1616

17-
That's because rules that set `this` do not look at object literals.
17+
That's because rules that set `this` do not look at object definition. Only the moment of call matters.
1818

19-
Here the value of `this` inside `makeUser()` is `undefined`, because it is called as a function, not as a method.
19+
Here the value of `this` inside `makeUser()` is `undefined`, because it is called as a function, not as a method with "dot" syntax.
2020

21-
And the object literal itself has no effect on `this`. The value of `this` is one for the whole function, code blocks and object literals do not affect it.
21+
The value of `this` is one for the whole function, code blocks and object literals do not affect it.
2222

2323
So `ref: this` actually takes current `this` of the function.
2424

@@ -53,5 +53,3 @@ alert( user.ref().name ); // John
5353
```
5454

5555
Now it works, because `user.ref()` is a method. And the value of `this` is set to the object before dot `.`.
56-
57-

1-js/04-object-basics/04-object-methods/7-calculator/task.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ importance: 5
66

77
Create an object `calculator` with three methods:
88

9-
- `read()` prompts for two values and saves them as object properties.
9+
- `read()` prompts for two values and saves them as object properties with names `a` and `b` respectively.
1010
- `sum()` returns the sum of saved values.
1111
- `mul()` multiplies saved values and returns the result.
1212

@@ -21,4 +21,3 @@ alert( calculator.mul() );
2121
```
2222

2323
[demo]
24-

1-js/04-object-basics/04-object-methods/article.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ let user = {
5151
// first, declare
5252
function sayHi() {
5353
alert("Hello!");
54-
};
54+
}
5555

5656
// then add as a method
5757
user.sayHi = sayHi;
@@ -90,7 +90,7 @@ user = {
9090

9191
As demonstrated, we can omit `"function"` and just write `sayHi()`.
9292

93-
To tell the truth, the notations are not fully identical. There are subtle differences related to object inheritance (to be covered later), but for now they do not matter. In almost all cases the shorter syntax is preferred.
93+
To tell the truth, the notations are not fully identical. There are subtle differences related to object inheritance (to be covered later), but for now they do not matter. In almost all cases, the shorter syntax is preferred.
9494

9595
## "this" in methods
9696

0 commit comments

Comments
 (0)