1

Please see the code below:

let xy = {name:"matt", age: 44};
let greetFunc = nickName => "Hello " + nickName + ". Your age is " + this.age + " now";
console.log(greetFunc.call(xy, "vms"));

The result is:

Hello vms. Your age is undefined now

Why is 'this.age' returning 'undefined'? Any help would be appreciated. Thanks.

AndrewL64
  • 15,794
  • 8
  • 47
  • 79
vinod-vms
  • 25
  • 6
  • this doesn't seem like a duplicate. the linked question and answers don't go into any depth about the `.call` method – worc Dec 07 '18 at 18:29
  • 1
    @worc: What more than *"Arrow functions don't have their own `this` or `arguments` binding."* and *"Note that this also means that is not possible to set an arrow function's `this` with `.bind` or `.call`."* (from my answer) do you expect? Which information is missing for you? – Felix Kling Dec 07 '18 at 18:38
  • it's buried in the answer. it's nice that there's a comprehensive wiki answer there, but that seems like a poor substitution for just answering the question – worc Dec 07 '18 at 18:42
  • i think the problem i'm seeing here is linking to a dense, comprehensive answer is more RTFM than anything especially useful or welcoming – worc Dec 07 '18 at 18:44
  • 1
    @worc: Then you might prefer this question , which was also closed as duplicate but has a short answer: https://stackoverflow.com/q/43062732/218196 – Felix Kling Dec 07 '18 at 18:56
  • yeah! that's a super concise answer. – worc Dec 07 '18 at 19:12
  • I see. Arrow functions are not equivalent to function declarations/expressions. Thanks. – vinod-vms Dec 08 '18 at 03:20

0 Answers0