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:

  1. you're in use strict mode, , in case this points nothing (null or undefined) , you'll see exception.

  2. you're not in use strict mode , this points window, in case you'll set bar global variable.

var keeps variable local (same scope run in) , not exposed outside calls of iife.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -