3
These days I was testing some Javascript features on Google Chrome 50
and I realized that it’s already been added to arrow function
for callbacks.
Thus:
$.each([1, 2, 3], x => x * 2);
// [2, 4, 6]
In the old days I’d have to do it like this:
$.each([1, 2, 3], function (x) { return x * 2; })
We can already use this option safely for all browsers (we are in 2016!), or I still have to wait a little longer?
You could have native JS instead of jQuery :) The less jQuery the better :P
– Sergio
@Sergio was just an example :D
– Wallace Maxters
As @Gabrielkatakura said, we still can’t do this directly. But you can use something like Typescript (http://www.typescriptlang.org/) that "compiles" for native JS, and you can use this syntax (plus many other things that JS doesn’t have)
– carlosfigueira
I know, it was kind of a joke. But I don’t know if join the jQuery tag if you change the examples to
[1, 2, 3].map(x => x * 2);
– Sergio