forked from bloominstituteoftechnology/JavaScript-III
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththis.js
More file actions
38 lines (31 loc) · 679 Bytes
/
Copy paththis.js
File metadata and controls
38 lines (31 loc) · 679 Bytes
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
/* The for principles of "this";
* in your own words. explain the four principle for the "this" keyword below.
*
* 1.
* 2.
* 3.
* 4.
*
* write out a code example of each explanation above
*/
// Principle 1
function birthday(when){
console.log(when);
return this;
}
birthday("082997");
// code example for Window Binding
// Principle 2
const getBirthday ={
birthday: '082997',
birth: function(time){
console.log(`${birthday} is mine yours is ${time}`)
console.log(this)
}
}
getBirthday.birth('20')
// code example for Implicit Binding
// Principle 3
// code example for New Binding
// Principle 4
// code example for Explicit Binding