public
Last active

IIFE: the simplest example i can contrive

  • Download Gist
simple-iife-example.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.