-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththisKeyword.js
42 lines (33 loc) · 866 Bytes
/
thisKeyword.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
var human = {
strech: function() {
console.log(this.hand);
},
hand: 'hand'
};
var dog = {
hand: 'paw'
};
dog.strech = human.strech;
console.log(dog);
dog.strech(); //"paw"
//The key is who streches.
/* --------------------------------------------------------- */
(function() {
(function() {
(function() {
(function() {
console.log(this);
})();
})();
})();
})(); //window.
//function can't be this. Only object or undefined.
/* ----------------------------------------------------------- */
/* 1. Called with a new?
2. Called with call or apply?
3. Called via a containing/owning object(context)?
4. Default: global/undefined */
/*
1. In the global execution context, this refers to the global object.
2.If a function is called as a method of an object, this in the function is bond to that object that object.
*/