Created
January 25, 2016 12:25
-
-
Save FernandoBasso/8dcd3edd7b613d5b3438 to your computer and use it in GitHub Desktop.
Using () to force a IIFE in ES5 functions vs in ES6 arrow functions
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
var l = console.log.bind(console); | |
// ↓ | |
var jedi1 = ((name, skill) => ({ | |
name: name, | |
skill: skill | |
}))('Master Yoda', 'The Force') ; | |
//↑ ↑ Can't close ) at the end. | |
l(jedi1.name); | |
l(jedi1.skill); | |
// → Master Yoda | |
// → The Force | |
// ↓ | |
var jedi2 = (function (name, skill) { | |
return { | |
name: name, | |
skill: skill | |
}; | |
}('Luke Skywalker', 'Lightsaber')); | |
// ↑ CAN close ) at the end. | |
l(jedi2.name); | |
l(jedi2.skill); | |
// → Luke Skywalker | |
// → Lightsaber |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment