angularjs - Global variables in JavaScript strict mode -
a simple javascript question, instance have angular app.js this;
'use strict'; var eventsapp = angular.module('eventsapp',[]);
i read using "use strict" in beginning of javascript file makes vars in file treated in strict mode, means throw error when use global variable(?), how can access "eventapp" object our controllers , services if that's not in global scope?
the faulty assumption in strict mode all global variables disallowed. undefined global variables throw error. (in fact couldn't @ if couldn't use any global variables. there has @ least in global scope.)
for example:
"use strict"; var = "foo"; var b; (function() { = "bar"; // ok, initialized earlier b = "baz"; // ok, defined earlier c = "qux"; // not, creating implicit global })();
using variables a
or b
not problem, c
throw error. there should no problems using eventapp
variable in example.
Comments
Post a Comment