Skip to content

Instantly share code, notes, and snippets.

@kishanio
Last active May 4, 2017 10:59
Show Gist options
  • Save kishanio/c014aeeb082417ae3c81bbeb75061d28 to your computer and use it in GitHub Desktop.
Save kishanio/c014aeeb082417ae3c81bbeb75061d28 to your computer and use it in GitHub Desktop.
ES6 : Arrow Function
// normal function defination
const someFunction = ( someArg, someArgDef = "Default Arg" ) => {
return someArg + " " + someArgDef;
}
console.log( someFunction( "Some Argument" ) );
// single line single argument short hand
const arr = ["a", "b", "c"];
const newArr = arr.map(a=>a);
console.log(newArr);
// arrow function can be more consise if they are returning just value
const notConsie = (text) => {
return {
text: text
}
};
// can be rewritten as
const concise = (text) => ({
text: text
});
console.log(concise("Arrow function just returning value"));
console.log(concise("Can be more consise now"));
// Also when a function is defined inside object
const example = () => {
return {
onClick: () => {
console.log("test");
},
}
};
// Can be rewritten as functions inside objects can have a consice way of representation
const example = () => ({
onClick() {
console.log("test");
},
});
const t = example();
t.onClick();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment