0

I found out that if I trying to bind an arrow function it's not working.

Working:

const person = {
name: 'itzik',
age: 21,
get: () => person.name+person.age
}
function logname () {console.log(this.get)}
const logPerson = logname.bind (person)
logPerson()

But if I change the function logName to an array function, like this:

const logName = () => console.log(this.get)

In this case, the this will reference to the window object. Why is that?

  • When you say array function, I think you mean arrow function. – Paul Jan 17 '18 at 00:30
  • Since when were keywords case-insensitive? – Austin Brunkhorst Jan 17 '18 at 00:30
  • yes, that's a 'gotcha' of using fat arrows. the are ways around it, and sometimes it even comes in pretty handy. check out this link: https://medium.freecodecamp.org/learn-es6-the-dope-way-part-ii-arrow-functions-and-the-this-keyword-381ac7a32881 – HolyMoly Jan 17 '18 at 01:16

0 Answers0