You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Arrow functions are normal JavaScript functions, except they keep the `this` context during execution. Extremely useful inside class methods that call to other async functions.
classFoo{
someMethod(arr: string[]){
arr.forEach(x=>this.log(x))
// Usually you'd have to `var self = this` and use `self.log(x)` in the callback, which is a much bigger function expression.
}
log(value: string){
console.log(value)
}
}
// Arrow functions can follow these syntaxes:
// * `<parameter> => <expression>`
// * `(<parameters?>) => <expression>`
// * `<parameter> => { <body> }`
// * `(<parameters?>) => { <body> }`
// When used with an expression, the expression is automatically "returned".
consthelp=()=>console.log('Help me, please!')
help()//=> "Help me, please!"
// Tip: Use the arrow function with libraries that use `this`, such as anything related to events in the browsers (jQuery, Angular, React).