Skip to content

Instantly share code, notes, and snippets.

@cowboy
Last active December 12, 2015 03:49
Show Gist options
  • Save cowboy/4710214 to your computer and use it in GitHub Desktop.
Save cowboy/4710214 to your computer and use it in GitHub Desktop.
IIFE: the simplest example i can contrive
var value, getValue;
value = 1;
getValue = function() { return value; };
value = 2;
getValue() // 2
var value, getValue;
value = 1;
getValue = (function(v) {
return function() { return v; };
}(value));
value = 2;
getValue() // 1
var value, getValue;
value = 1;
(function(v) {
getValue = function() { return v; };
}(value));
value = 2;
getValue() // 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment