folder 01
Did you define the function with an arrow function? 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
const colors = {
printColor() {
console.log(this)
},
}
colors.print()const colors = {
printColor() {
console.log(this)
const printThis = () => {
console.log(this)
}
printThis()
},
}
colors.print()Did you call 'bind', 'call' or 'apply' on the function when you invoked it? R// 'this' is equal to the first argument of 'bind', 'call' or 'apply
bind, call and apply are built-in functions that belong to all functions inside of JavaScript that we create
const printThis = function () {
console.log(this)
}
printThis.call({ color: 'red' })
printThis.apply({ color: 'red' })'this' is equal to whatever is to the left of the '.' in the method call
const colors = {
printColor() {
console.log(this)
},
}
const randomObject = {
a: 1,
}
randomObject.printColor = colors.printColor
randomObject.printColor()class Timer {
constructor(durationInput, startButton, pauseButton) {
this.durationInput = durationInput
this.startButton = startButton
this.pauseButton = pauseButton
// start(){}, Calling the constructor anytime the user clicks on the start button
this.startButton.addEventListener('click', this.start)
this.pauseButton.addEventListener('click', this.pause)
}
// start() {
// // console.log('Time to start the timer!');
// console.log(this);
// }
start = () => {
// This runs on tick immediately
this.tick()
// const timer = setInterval(this.tick, 1000)
this.interval = setInterval(this.tick, 1000)
console.log(timer)
// function that is built into the browser
// clearInterval(timer)
}
pause = () => {
clearInterval(this.interval)
}
tick = () => {
console.log('tick')
}
} getTime() {
return parseFloat(this.durationInput.value)
}
setTime() {
return this.durationInput = time
} tick = () => {
console.log('tick')
this.timeRemaining = this.timeRemaining - 1
}
get timeRemaining() {
return parseFloat(this.durationInput.value)
}
set timeRemaining(time) {
this.durationInput.value = time
}tick = () => {
console.log('tick')
if (this.timeRemaining <= 0) {
this.pause()
} else {
this.timeRemaining = this.timeRemaining - 1
}
}// The fourth argument is going to be totally optional so we can use our timer with or without fourth argument
const timer = new Timer(durationInput, startButton, pauseButton, {
onStart() {
console.log('Timer started')
},
onTick() {},
onComplete() {},
}) constructor(durationInput, startButton, pauseButton, callbacks) {
this.durationInput = durationInput
this.startButton = startButton
this.pauseButton = pauseButton
// Callbacks are optional (logic for that)
if (callbacks) {
this.onStart = callbacks.onStart
}
this.startButton.addEventListener('click', this.start)
this.pauseButton.addEventListener('click', this.pause)
}if (callbacks) {
this.onStart = callbacks.onStart
this.onTick = callbacks.onTick
this.onComplete = callbacks.onComplete
}tick = () => {
if (this.timeRemaining <= 0) {
this.pause()
if (this.onComplete) {
this.onComplete()
}
} else {
this.timeRemaining = this.timeRemaining - 1
if (this.onTick) {
this.onTick()
}
}
}folder 02
<svg height="200" widht="200">
<circle r="20" cx="30" cy="30" />
</svg>The X axis increases from left to right and the Y axis increases from top to bottom
<circle
r="90"
cx="100"
cy="100"
fill="transparent"
stroke="blue"
stroke-width="10"
stroke-dasharray="560"
stroke-dashoffset="-100"
/>transform="rotate(-90, 100, 100)"