Skip to content

Commit f870ad6

Browse files
committed
Section 20: Determining the Value of 'This' DONE
1 parent b616e29 commit f870ad6

1 file changed

Lines changed: 34 additions & 1 deletion

File tree

20-Drawing-Animations/README.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
#### Determining the value of this inside of an arrow function
88

9+
Did you define the function with an arrow function?
10+
R// Write 'console.log(this)' on the first **valid** line above the arrow function. Value of 'this' in the arrow function will be equal to that console log
11+
912
```javascript
1013
const colors = {
1114
printColor() {
@@ -32,4 +35,34 @@ colors.print()
3235

3336
#### Calling the function with bind, call or apply
3437

35-
**bind, call and apply** are built-in functions that belong to all functions inside of JavaScript that we create
38+
Did you call 'bind', 'call' or 'apply' on the function when you invoked it?
39+
R// 'this' is equal to the first argument of 'bind', 'call' or 'apply
40+
41+
**bind, call and apply** are built-in functions that belong to all functions inside of JavaScript that we create
42+
43+
```javascript
44+
const printThis = function() {
45+
console.log(this)
46+
}
47+
48+
printThis.call({ color: 'red'})
49+
printThis.apply({ color: 'red'})
50+
```
51+
52+
#### All other cases
53+
'this' is equal to whatever is to the left of the '.' in the method call
54+
55+
```javascript
56+
const colors = {
57+
printColor() {
58+
console.log(this)
59+
}
60+
}
61+
62+
const randomObject = {
63+
a: 1
64+
}
65+
66+
randomObject.printColor = colors.printColor
67+
randomObject.printColor()
68+
```

0 commit comments

Comments
 (0)