3 ms·
I use this function to create namespaces: var namespace = function(ns) { var scope = window; var tokens = ns.split("."); for (var idx = 0, len =
by nkohari 17y ago
I use this function to create namespaces:
var namespace = function(ns) {
var scope = window;
var tokens = ns.split(".");
for (var idx = 0, len = tokens.length; idx < len; idx++) {
var token = tokens[idx];
scope = scope[token] = scope[token] || {};
}
};
For example: namespace("Zen.Ui");
- yannis 17y agoClever! How do you add your properties and methods? Another clever trick?
- woadwarrior01 17y agoYAHOO.namespace in YUI does the same thing, except that it creates everything under the YAHOO namespace.