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 = {}

Published Tuesday, July 18, 2006 10:05 AM by Michael Schwarz

Comments

# re: Why addNamespace(...) is removed?

Tuesday, July 18, 2006 2:31 PM by Bertrand Le Roy
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.

# Choose your Ajax Toolkit

Tuesday, July 18, 2006 5:43 PM by Ajax Tuotrials
Ajax Projects is a portal for all ajax resources. it includes reviews for most of the toolkits and frameworks. it will help you to have the decision which framework or toolkit you will use in your project http://www.ajaxprojects.com

# re: Why addNamespace(...) is removed?

Monday, August 14, 2006 11:11 AM by Ryan
I have tried to run the example code from schwartz-interactive and I have been getting a "namespace not defined" error...I have tried everything I can find on the error but cannot get it to work. It appears that the code is not even creating the ahsx files at all, so I cannot get into my source and figure out what namespace and class name I need to use in my code. Any suggetions would be great...would the code you added in this thread be a solution for my problem possibly? Thank You in advance... Ryan Tracy Programmer Analyst II Ryan.Tracy@cityofthornton.net

# re: Why addNamespace(...) is removed?

Friday, August 18, 2006 5:33 AM by percyboy
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

# re: Why addNamespace(...) is removed?

Friday, September 01, 2006 10:28 AM by Ric

I agree - cann't you just re-write the function?

addNamespace ("A.B.C")

split by "."

forEach - if(typeof(part) ...