Skip to content

Instantly share code, notes, and snippets.

@FernandoBasso
Created January 25, 2016 12:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FernandoBasso/8dcd3edd7b613d5b3438 to your computer and use it in GitHub Desktop.
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
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