Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- console.log('Global this', this)
- personA = {
- 'name': 'Stella',
- 'yob': 1986,
- 'age1': function() {
- console.log('Age1 is:', 2020 - this.yob)
- },
- 'age2': () => {console.log('Age2 is:', this.yob)}
- }
- personA.age1() // output: 34s
- personA.age2() // output: undefined
- function personB() {
- this.name = 'Thomas'
- this.yob = 1991
- this.age3 = function() {console.log('Age3 is:', 2020 - this.yob)}
- this.age4 = () => {console.log('Age4 is:', 2020 - this.yob)}
- }
- personX = new personB()
- personX.age3() // output: 29
- personX.age4() // output: 29
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement