【发布时间】:2016-09-15 02:35:03
【问题描述】:
我有一个 json 对象,它的属性是一个嵌套的 json。嵌套的 json 具有作为属性的功能。我想从那个内部 json 中的那个函数访问那个外部 json 中的一个属性。
让我用一个虚拟代码解释一下,
{
name: "Barry Allen",
getName: function () {
return this.name; //this is returning "Barry Allen", which is fine
},
nestedJson: {
getName: function () {
//here I want something like return this.parent.name
}
}
}
我想从nestedJson 的getName 访问name。可能吗? json中是否有父子遍历机制/方式,javascript中是否有嵌套json对象?
提前致谢。
【问题讨论】:
-
这不是 JSON,JSON 不支持函数。这是一个 JavaScript 对象。
-
对不起,我不知道
标签: javascript json