Skip to content

Instantly share code, notes, and snippets.

@w3cj
Last active May 11, 2016 17:13
Show Gist options
  • Save w3cj/6aa78c47b0dcaa9e9762fc71ce7f394d to your computer and use it in GitHub Desktop.
Save w3cj/6aa78c47b0dcaa9e9762fc71ce7f394d to your computer and use it in GitHub Desktop.
When creating an iife, use a function, NOT a fat arrow. With a fat arrow, this is bound to the this of the surrounding code (in this case Window or Global), negating the use of an iife (to prevent polluting global scope).
// When creating an iife, use a function, NOT a fat arrow.
// With a fat arrow, this is bound to the this of the surrounding code (in this case Window or Global).
// Therefore, using a fat arrow negates the use of an iife (to prevent polluting global scope).
(() => {
'use strict';
console.log('fat arrow', this)
})();
(function(){
'use strict';
console.log('function', this)
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment