javascript如何模拟Json语句的函数全局作用域?
var testJson=
{
a1: 1,
a2: this.a1+1
}
结果应该是:
var testJson=
{
a1: 1,
a2: 2
}
最佳答案
您必须在 testJson
外部定义一个变量,或者使用函数作为 a2
的值,如下所示:
var testJson = {
a1: 1,
a2: function () {
return this.a1 + 1;
}
};
关于javascript如何模拟Json语句的函数全局作用域?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2884642/