-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharrowfunctionsthis.js
More file actions
33 lines (30 loc) · 1.09 KB
/
arrowfunctionsthis.js
File metadata and controls
33 lines (30 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// JavaScript Arrow Functions with 'this'
// this keyword works with arrow functions
const skaterDude = {
name: 'Jason',
stance: 'regular',
favTrick: '360 flips',
// doTrick() {
// better syntax ^^
doTrick: function () {
// This this keyword refers to the parent object which is skaterDude
console.log('Droppin hammers with some ' + this.favTrick);
//you would have to do something sketchy like this to make this work
// const self = this;
// const forDayzz = () => {
//console.lof('I could do ' + this.favTrick + ' for dayzzz!');
//}
//forDayzz();
//}
//}
// this keyword inside of a function will inhearit from the parent object on the top which in this case is skaterDude
const forDayzz = function() {
// this this is in a different scope and is looking at the doTrick function object
// can now turn the this to self.favTrick
// the reference will be available in the next block below
console.log('I could do ' + this.favTrick + ' for dayzzz!');
}
forDayzz();
}
}
skaterDude.doTrick();