javascript - IIFE: var vs this - is there any difference? -
is there difference between this , var in invoced function expressions(iife)?
(function(){ var foo = 0; this.bar = 0; })();
if code executed in global context, 2 options:
you're in
use strictmode, , in casethispoints nothing (null or undefined) , you'll see exception.you're not in
use strictmode ,thispoints window, in case you'll setbarglobal variable.
var keeps variable local (same scope run in) , not exposed outside calls of iife.
Comments
Post a Comment