Skip to content

Commit b616e29

Browse files
committed
Section 20: Determining the Value of 'This' pt1
1 parent 29201a6 commit b616e29

2 files changed

Lines changed: 37 additions & 4 deletions

File tree

20-Drawing-Animations/01-timer/index.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,20 @@ class Timer {
88
this.pauseButton = pauseButton
99

1010
// start(){}, Calling the constructor anytime the user clicks on the start button
11-
this.startButton,addEventListener('click', this.start)
11+
this.startButton.addEventListener('click', this.start)
1212
}
1313

1414
start() {
15-
console.log('Time to start the timer!');
15+
// console.log('Time to start the timer!');
16+
console.log(this);
1617
}
1718
}
1819

1920
const durationInput = document.querySelector('#duration')
20-
const startButton = document.querySelector('#pause')
21+
const startButton = document.querySelector('#start')
2122
const pauseButton= document.querySelector('#pause')
2223

2324
// Create our instance of the timer and pass in those three elements
2425
const timer = new Timer(durationInput, startButton, pauseButton)
26+
27+
timer.start()

20-Drawing-Animations/README.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,34 @@
22

33
## 1. 06 Binding Events in a Class
44

5-
##
5+
## 2. 08 Determining the Value of 'This'
6+
7+
#### Determining the value of this inside of an arrow function
8+
9+
```javascript
10+
const colors = {
11+
printColor() {
12+
console.log(this)
13+
},
14+
}
15+
16+
colors.print()
17+
```
18+
19+
```javascript
20+
const colors = {
21+
printColor() {
22+
console.log(this)
23+
const printThis = () => {
24+
console.log(this)
25+
}
26+
printThis()
27+
},
28+
}
29+
30+
colors.print()
31+
```
32+
33+
#### Calling the function with bind, call or apply
34+
35+
**bind, call and apply** are built-in functions that belong to all functions inside of JavaScript that we create

0 commit comments

Comments
 (0)