【发布时间】:2020-01-12 23:02:12
【问题描述】:
我创建了以下变量:
var orientations = {
E: {R: this.S, L: this.N},
W: {R: this.N, L: this.S},
N: {R: this.E, L: this.W},
S: {R: this.W, L: this.E},
}
我正在尝试引用我的 orientations 对象,但在我的代码中,“this”引用了窗口对象。我猜这可能是因为我深入到物体的两层。 有没有办法引用 orientations 对象本身?
【问题讨论】:
-
这段代码是否在事件处理程序中,例如
DOMContentLoaded?这可以解释为什么this === window。
标签: javascript object this javascript-objects