在下面的代码中,可以从嵌套对象文字中访问x成员吗?
var outer = { x : 0,inner: { a : x + 1,// 'x' is undefined. b : outer.x + 1,// 'outer' is undefined. c : this.x + 1 // This doesn't produce an error,} // but outer.inner.c is NaN. }
解决方法
在你说的方式 – 没有.
你需要两个阶段的构造,这将工作:
var outer = { x : 0 }; // outer is constructed at this point. outer.inner = { b : outer.x + 1 // 'outer' is defined here. };
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。