var YourGlobal = {
namespace: function(ns) {
var parts = ns.split('.'),
object = this,
i, len;
for(i =0, len=parts.length; i<len; i++) {
if(!object[parts[i]]) {
object[parts[i]] = {};
}
object = object[parts[i]];
}
return object;
}
};
YourGlobal.namespace("Book.MaintainableJS").author='caprice.liu';
/* 动态创建了命名空间,并链式调用 */
来自《编写可维护javascript》