Skip to content

Commit 182dbeb

Browse files
committed
adds code examples for principles 1 & 2 of this.js
1 parent 55d5a59 commit 182dbeb

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

‎assignments/this.js‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,30 @@
44
* 1. When "this" is globally scoped, "this" refers to the uber-Object, the form of forms, the great prototype of prototypes
55
* 2. When "this" is used within the method of an object, and then that method is called on that object, "this" refers to that object.
66
* 3. When "this" is used within a constructor, calling that constructor makes "this" refer to the specific instance of the class that is created by that call.
7-
* 4. Using "call" or "apply" together with a parameter can override "this"'s default application to a constructed instance in favor of applying to a different constructed instance.
7+
* 4. Using "call" or "apply" together with a parameter can override "this"'s default application to a constructed instance in favor of applying to a different constructed instance.
88
*
99
* write out a code example of each explanation above
1010
*/
1111

1212
// Principle 1
1313

1414
// code example for Window Binding
15-
15+
const thisLogger = function(){
16+
console.log(this);
17+
}
18+
thisLogger();
1619
// Principle 2
1720

1821
// code example for Implicit Binding
22+
const impliciturBinder = {
23+
favoriteImplicationForm: "insinuation",
24+
findFave: function() {
25+
console.log(`${this.favoriteImplicationForm} is the best form of implication`);
26+
}
27+
}
28+
29+
impliciturBinder.findFave();
30+
1931

2032
// Principle 3
2133

0 commit comments

Comments
 (0)