An arrow function is nothing more than the shorter syntax for declaring function expression.
This statement is incorrect. Though arrow function can be used for this purpose, its primary purpose is sharing context (this) with parent scope, which makes such functions ideal for passing as arguments to when calling function that can then execute it.
Prior to arrow functions introduction we would have to bind a function context when passing it as argument, as context would be lost otherwise.
classGreeter{greeting='hello';say1=(name)=>this.greeting+''+name;say2(name){returnthis.greeting+''+name;}}functionsayHi(name,greeterFn){console.log(greeterFn(name));}vargreeter=newGreeter();sayHi('Bob',greeter.say1);// 'hello Bob'// context is lost when passing function as argument of another functionsayHi('Bob',greeter.say2);// ' Bob'// bind contextsayHi('Bob',greeter.say2.bind(greeter));// 'hello Bob'
The over simplification of what arrow functions are is really concerning for an article with such an audacious title.
There’s no mention of the fact that this within an arrow function will always try to find the nearest defined this at that scope.
No mention of the fact that bind is still there and you can still bind arrow functions for achieving some sort of currying approach.
Also there’s no mention that the keyword arguments will behave just like the keyword this, and not like a regular function.
And last but not least, there’s no mention of some of the nicest things about the arrow functions which is the possibility of not using the return keyword
I vouch for a more humble name for the article.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
This statement is incorrect. Though arrow function can be used for this purpose, its primary purpose is sharing context (this) with parent scope, which makes such functions ideal for passing as arguments to when calling function that can then execute it.
Prior to arrow functions introduction we would have to bind a function context when passing it as argument, as context would be lost otherwise.
Thanks for pointing that. You are right. I should mention this :)
The over simplification of what arrow functions are is really concerning for an article with such an audacious title.
There’s no mention of the fact that this within an arrow function will always try to find the nearest defined this at that scope.
No mention of the fact that bind is still there and you can still bind arrow functions for achieving some sort of currying approach.
Also there’s no mention that the keyword arguments will behave just like the keyword this, and not like a regular function.
And last but not least, there’s no mention of some of the nicest things about the arrow functions which is the possibility of not using the return keyword
I vouch for a more humble name for the article.