Reputation: 1785
In Mozilla's sample code for Downloads.jsm there's a few lines that use =>
which I don't know the meaning of:
let view = {
onDownloadAdded: download => console.log("Added", download),
onDownloadChanged: download => console.log("Changed", download),
onDownloadRemoved: download => console.log("Removed", download),
};
What does =>
do here?
Upvotes: 3
Views: 95
Reputation: 100381
That is called "arrow functions" or "lambda expressions".
If you want to use that and not wait for ECMAScript 6, you can have a look at typescript , you don't have to worry about browser compatibility and this kind of stuff.
You can check an example here.
Upvotes: 1
Reputation:
It's the syntax of upcoming version of JavaSctipt, the ECMAScript 6, aka Harmony.
The x => expr
syntax stands, more or less (with differences with treatment of this
), for function (x) { return expr; }
.
Upvotes: 2
Reputation: 665276
They're a special function literal notation, called arrow functions, introduced with ES6. It's basically the same as in coffeescript.
It could have been shorter written as console.bind(console, "Added")
:-)
Upvotes: 3