这是一个扩展函数,需要初期加载的时候加载到适当的位置。

具体函数体如下:

$.namespace = function() {
    var a=arguments, o=null, i, j, d;
    for (i=0; i<a.length; i=i+1) {
        d=a[i].split(".");
        o=window;
        for (j=0; j<d.length; j=j+1) {
            o[d[j]]=o[d[j]] || {};
            o=o[d[j]];
        }
    }
    return o;
};

使用的时候这样写,可以避免一长串的对象赋值:

$.namespace('system.user');


$.system.user.funcA = function(){
}

 

相关文章: