javascript - 遍历 JavaScript 对象

标签 javascript object

是否可以在 JavaScript 中导航对象,引用另一个“区域”/对象的部分?

例如,如果我有一个结构如下的对象:

var config = {
    resources: {
        styles: 'path/to/a/stylesheet',
        scripts: 'path/to/a/javascript/file'
    },
    options: {
        plugin_a: {
            entries: [config.resources.styles, config.resources.scripts]
        }
    }
}

例如,我是否可以在“config.options.plugin_a”部分的“config.resources.styles”和“config.resources.scripts”中引用样式和脚本文件的路径?

谢谢

最佳答案

您可以用两行单独的代码来完成:创建配置对象,然后使用配置值将 config.options 设置为该对象。 使用 var a={b:1}; 而不是 var a={b:1,c:a.b} a.c=a.b;

关于javascript - 遍历 JavaScript 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36103341/

相关文章:

javascript - Agility.js + jQueryUI,将参数传递给 Controller ​​中的事件处理程序

c++如何跨多个类对同一对象进行更改?

javascript - 使用lodash的extend方法扩展JS对象实例会导致奇怪的结果

javascript - JS - 函数取双结果

javascript - 我使用 React 时遇到错误 : "Invalid DOM property ` for`. 您的意思是 `htmlFor` 吗?

javascript - AngularJS View Animation Mystery—elements render at wrong position 然后 resolve

javascript - 在Google应用程序脚本GUI中显示Gmail消息

javascript - 如何通过 id 删除特定对象并将其重新添加到数组中 [jQuery]

java - 当子对象引用父对象时对象销毁

javascript - 使用递归函数遍历 JSON 字符串到内部级别