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 strict
mode, , in casethis
points nothing (null or undefined) , you'll see exception.you're not in
use strict
mode ,this
points window, in case you'll setbar
global variable.
var
keeps variable local (same scope run in) , not exposed outside calls of iife.
Comments
Post a Comment