给定 JavaScript 对象内的 Array Literal,访问其自身对象的属性似乎不起作用:
var closure = {
myPic : document.getElementById('pic1'),
picArray: [this.myPic]
}
alert(closure.picArray[0]); // alerts [undefined]
而通过访问其他 JavaScript 对象来声明一个数组项似乎有效
var closure1 = {
myPic : document.getElementById('pic1')
}
var closure2 = {
picArray: [closure1.myPic]
}
alert(closure2.picArray[0]); // alerts [object HTMLDivElement]
示例:http:
//jsfiddle.net/5pmDG/