gpt4 book ai didi

JavaScript 对象嵌套

转载 作者:行者123 更新时间:2023-11-28 05:28:45 26 4
gpt4 key购买 nike

我昨天在这里工作,将一些旧的意大利面条 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;
}
})();

最佳答案

很容易:

var a = obj.insideObj1.moreInsideObj1.evenMoreInsideObj1;
var b = obj.insideObj1.moreInsideObj1.evenMoreInsideObj2;
var c = obj.insideObj1.moreInsideObj1.evenMoreInsideObj2;
var d = obj.insideObj1.moreInsideObj2;

只需添加另一个点即可更深。

关于JavaScript 对象嵌套,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39900161/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com