Skip to main content
952 votes
11 answers
746k views

I can mark a JavaScript function as "async" (i.e., returning a promise) with the async keyword. Like this: async function foo() { // Do something } What is the equivalent syntax for arrow ...
BonsaiOak's user avatar
  • 29.1k
888 votes
6 answers
166k views

When returning an object from an arrow function, it seems that it is necessary to use an extra set of {} and a return keyword because of an ambiguity in the grammar. That means I can’t write p => {...
Jonathan Schneider's user avatar
844 votes
3 answers
272k views

Arrow functions in ES2015 provide a more concise syntax. Can I replace all my function declarations / expressions with arrow functions now? What do I have to look out for? Examples: Constructor ...
Felix Kling's user avatar
748 votes
7 answers
188k views

I have been reading a bunch of React code and I see stuff like this that I don't understand: handleChange = field => e => { e.preventDefault(); /// Do something here }
jhamm's user avatar
  • 25.1k
521 votes
14 answers
429k views

I know that the >= operator means more than or equal to, but I've seen => in some source code. What's the meaning of that operator? Here's the code: promiseTargetFile(fpParams, aSkipPrompt, ...
rpgs_player's user avatar
  • 5,469
515 votes
9 answers
157k views

With () => {} and function () {} we are getting two very similar ways to write functions in ES6. In other languages lambda functions often distinguish themselves by being anonymous, but in ...
lyschoening's user avatar
  • 18.8k
388 votes
8 answers
144k views

That is, how do I express function *(next) {} with arrow syntax? I've tried all the combinations I could think of, and I can't find any documentation on it. (I am currently using Node.js v0.11.14.)
Ashley Coolman's user avatar
263 votes
8 answers
131k views

I have a function that I am trying to convert to the new arrow syntax in ES6. It is a named function: function sayHello(name) { console.log(name + ' says hello'); } Is there a way to give it a ...
jhamm's user avatar
  • 25.1k
220 votes
4 answers
158k views

I'm new to using ES6 classes with React, previously I've been binding my methods to the current object (show in first example), but does ES6 allow me to permanently bind a class function to a class ...
Ben's user avatar
  • 5,381
214 votes
4 answers
124k views

Why does this work in a Node.js console (tested in 4.1.1 and 5.3.0), but doesn't work in the browser (tested in Chrome)? This code block should create and invoke an anonymous function that logs Ok. () ...
XCS's user avatar
  • 28.3k
210 votes
6 answers
120k views

The new ES6 arrow functions say return is implicit under some circumstances: The expression is also the implicit return value of that function. In what cases do I need to use return with ES6 arrow ...
Jess Telford's user avatar
  • 13.3k
183 votes
9 answers
150k views

I'm running lint with my React app, and I receive this error: error JSX props should not use arrow functions react/jsx-no-bind And this is where I'm running the arrow function (inside ...
KadoBOT's user avatar
  • 3,174
182 votes
4 answers
105k views

I came across this construct in an Angular example and I wonder why this is chosen: _ => console.log('Not using any parameters'); I understand that the variable _ means don't care/not used but ...
Halt's user avatar
  • 2,994
180 votes
3 answers
127k views

The export statement below gives a syntax error export default const hello = () => console.log("say hello") why ? I'm only able to export named functions export function hello() { console.log(...
jozzy's user avatar
  • 2,943
172 votes
5 answers
88k views

Using ES6 arrow functions with lexical this binding is great. However, I ran into an issue a moment ago using it with a typical jQuery click binding: class Game { foo() { self = this; this....
JRodl3r's user avatar
  • 1,848

15 30 50 per page
1
2 3 4 5
102