我昨天在这里工作,将一些旧的意大利面条jquery代码转换为模块化模式然后我开始考虑这个问题:
我该怎么做这样的事情? 这可能吗?
var obj = {
insideObj1: {
moreInsideObj1: {
evenMoreInsideObj1: {
//How could I reference the "moreInsideObj1" from here
},
evenMoreInsideObj2: {
//How could I reference the "insideObj1" from here
},
evenMoreInsideObj2: {
//How could I reference the "obj" from here
}
},
moreInsideObj2: {
//How could I do the same thing here
},
},
insideObj2: {
//Here I can use "this.insideObj1" right;
}
};
**我是JS和JQuery世界的新手。
这样的事情:
var obj = (function(){
insideObj1: {
moreInsideObj1: {
evenMoreInsideObj1: {
//How could I reference the "moreInsideObj1" from here
},
evenMoreInsideObj2: {
//How could I reference the "insideObj1" from here
},
evenMoreInsideObj2: {
//How could I reference the "obj" from here
}
},
moreInsideObj2: {
//How could I do the same thing here
},
},
insideObj2: {
//Here I can use "this.insideObj1" right;
}
})();
答案 0 :(得分:0)
很容易:
var a = obj.insideObj1.moreInsideObj1.evenMoreInsideObj1;
var b = obj.insideObj1.moreInsideObj1.evenMoreInsideObj2;
var c = obj.insideObj1.moreInsideObj1.evenMoreInsideObj2;
var d = obj.insideObj1.moreInsideObj2;
只需添加另一个点即可更深入。