Skip to content

Commit 2f1f2d5

Browse files
committed
answers
1 parent 7975fd3 commit 2f1f2d5

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

‎assignments/this.js‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
/* The for principles of "this";
1+
/* The four principles of "this";
22
* in your own words. explain the four principle for the "this" keyword below.
33
*
4-
* 1.
5-
* 2.
6-
* 3.
7-
* 4.
4+
* 1. when 'this' is in global scope, it refrences the window or console object.
5+
* 2. implicit binding: when object.function is called, 'this' (in the function) refers to the the object preceding the dot.
6+
* 3. new binding: when the 'new' keyword is used to create an instance of an object, 'this' in the constructor funtion refers to that
7+
object instance.
8+
* 4. explicit binding: the 'call' and 'apply' methods explicitly state which object 'this' refers to.
89
*
910
* write out a code example of each explanation above
1011
*/
@@ -13,10 +14,13 @@
1314

1415
// code example for Window Binding
1516

17+
console.log(this);
18+
1619
// Principle 2
1720

1821
// code example for Implicit Binding
1922

23+
2024
// Principle 3
2125

2226
// code example for New Binding

0 commit comments

Comments
 (0)