Created
March 6, 2017 20:33
-
-
Save mowat27/9ecc8388c822f35e1792b8758dffc515 to your computer and use it in GitHub Desktop.
Example of why ES6 is cool
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Converting an ES5 function ES6 | |
// Start | |
function getWords(text) { | |
return text.split(/\s/) | |
} | |
// Use const declaration | |
const getWords = function(text) { | |
return text.split(/\s/) | |
} | |
// Convert to fat arrow | |
const getWords = (text) => { | |
return text.split(/\s/) | |
} | |
// Use round brackets | |
const getWords = (text) => ( | |
return text.split(/\s/) | |
) | |
// return is now implicit | |
const getWords = (text) => ( | |
text.split(/\s/) | |
) | |
// But we don't need brackets for a one liner | |
const getWords = (text) => text.split(/\s/) | |
// ... or parens in the args list | |
const getWords = text => text.split(/\s/) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment