Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save afuggini/61a2cb1bfeb72105d0c1708d5186d814 to your computer and use it in GitHub Desktop.
Save afuggini/61a2cb1bfeb72105d0c1708d5186d814 to your computer and use it in GitHub Desktop.
// #1 ES6: if passing one argument you don't need to include parenthesis around parameter.
var kitty = name => name;
// same as ES5:
var kitty = function(name) {
return name;
};
// #2 ES6: no parameters example.
var add = () => 3 + 2;
// same as ES5:
var add = function() {
return 3 + 2;
};
// #3 ES6: if function consists of more than one line or is an object, include braces.
var objLiteral = age => ({ name: "Usagi", age: age });
// same as ES5:
var objLiteral = function(age) {
return {
name: "Usagi",
age: age
};
};
// #4 ES6: promises and callbacks.
asyncfn1().then(() => asyncfn2()).then(() => asyncfn3()).done(() => done());
// same as ES5:
asyncfn1().then(function() {
asyncfn2();
}).then(function() {
asyncfn3();
}).done(function() {
done();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment