Why addNamespace(...) is removed?
I removed addNamespace because of the missing support on older web browsers or mobile devices. The problem is that addNamespace will add a new property to the window object. This is working great on all common web browsers. See the next lines to see how you can change addNamespace usage to get your JavaScript working on all web browsers.
Old way:
addNamespace("Company.Utils.Web");
New way:
if(typeof(Company) == "undefined") Company = {};
if(typeof(Company.Utils) == "undefined") Company.Utils = {};
if(typeof(Company.Utils.Web) == "undefined") Company.Utils.Web = {}
3 Comments
Comments have been disabled for this content.
Bertrand Le Roy said
That will get you warnings in Firefox because of the undeclared variables. To enable warnings in the Firefox console, go to the about:config url and enable option strict.
percyboy said
why not rewrite the addNamespace implementation using the javascript "eval" function? just like: if(!window.addNamespace) { window.addNamespace = function(ns) { var nsParts = ns.split("."); var root = window; for(var i=0; i<nsParts.length; i++) { if(eval("typeof("+ root[nsParts[i]] + ")" == "undefined") eval(root[nsParts[i]] + " = {};"); root = eval(root[nsParts[i]]); } } }
Ric said
I agree - cann't you just re-write the function? addNamespace ("A.B.C") split by "." forEach - if(typeof(part) ...