Javascript Namespace - Is this a good pattern?
问题 Objectives... Remove vars, objects etc from the global object. Remove possibility of collisions. Firstly I implement the Yahoo namespace code (note for example purposes I am using ROOT as the root of my namespace)... if (typeof ROOT == "undefined" || !ROOT) { var ROOT = {}; } ROOT.namespace = function () { var a = arguments, o = null, i, j, d; for (i = 0; i < a.length; i = i + 1) { d = ("" + a[i]).split("."); o = ROOT; for (j = (d[0] == "ROOT") ? 1 : 0; j < d.length; j = j + 1) { o[d[j]] = o