up
This commit is contained in:
parent
5372c18379
commit
3defacc09d
314 changed files with 1761 additions and 1704 deletions
26
1-js/4-object-basics/04-object-methods/3-why-this/task.md
Normal file
26
1-js/4-object-basics/04-object-methods/3-why-this/task.md
Normal file
|
@ -0,0 +1,26 @@
|
|||
importance: 3
|
||||
|
||||
---
|
||||
|
||||
# Explain the value of "this"
|
||||
|
||||
In the code above we intend to call `user.go()` method 4 times in a row.
|
||||
|
||||
But calls `(1)` and `(2)` works differently from `(3)` and `(4)`. Why?
|
||||
|
||||
```js run no-beautify
|
||||
let obj, method;
|
||||
|
||||
obj = {
|
||||
go: function() { alert(this); }
|
||||
};
|
||||
|
||||
obj.go(); // (1) [object Object]
|
||||
|
||||
(obj.go)(); // (2) [object Object]
|
||||
|
||||
(method = obj.go)(); // (3) undefined
|
||||
|
||||
(obj.go || obj.stop)(); // (4) undefined
|
||||
```
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue