0

Previously, I learned lambda as shorten way to make instance of function(I learned from C# book), but when I used lambda with Vue.js, I encountered a problem. This works well:

mounted: function(){ (...) 

But this not works:

mounted: () => { (...) }

I want to get perfect explanation for this.

str
  • 42,689
  • 17
  • 109
  • 127
anesin1109
  • 315
  • 3
  • 13
  • The context of `this` is saved using arrow functions. I wouldn't be surprised that the this context is wrong at time of declaration, but having only 1 function it's hard to say – Icepickle Nov 06 '17 at 08:17
  • Also to clear the confusion: What is a lambda function: https://stackoverflow.com/questions/16501/what-is-a-lambda-function – teroi Nov 06 '17 at 08:17
  • See the note about arrow functions: https://vuejs.org/v2/guide/instance.html#Instance-Lifecycle-Hooks – str Nov 06 '17 at 08:19
  • 1
    Don't try to infer anything from C# to JS. Despite the syntactic similarity to lambdas, arrow functions are just one syntax amongst many for creating inline functions in JS. – Bergi Nov 06 '17 at 08:26

0 Answers0