我有一个如下所示的对象。
在第 6 行,我写了console.log(this.title, elem)
.
现在根据我了解到的情况。-Keyword,this.title
这里不应该引用当前的Object,而是全局的Window-Object。现在与我的知识相反,this.title
似乎正确引用了视频对象的属性。
const video = {
title: "a",
tags: ["a", "b", "c", "d"],
showTags() {
this.tags.forEach(elem => {
console.log(this.title + ": ", elem)
});
}
}
video.showTags();
这是浏览器显示的内容:
a: a
a: b
a: c
我想,既然console.log(this.title, elem)
在回调函数内部,就会引用全局窗口对象。这篇文章证实了我this.title
应该实际引用全局对象的概念。
有人可以解释一下吗?