gpt4 book ai didi

javascript - 为什么 'this' 在调试器中未定义但可在 console.log 中打印?

转载 作者:行者123 更新时间:2023-11-29 17:43:56 24 4
gpt4 key购买 nike

console.log 语句上设置断点时,为什么 this 在调试器中未定义但语句打印没有问题?我是否遗漏了有关范围的内容?

export class OptionsSidebarComponent {

...

public filters: Object = new Object();

...

public generateFilters() {
for (let property in this.terms) {
if (this.terms.hasOwnProperty(property) && this.terms[property] !== null) {

if (!this.filters.hasOwnProperty(this.productGroup.id)){
this.filters[this.productGroup.id] = new Filters();
}

this.terms[property].forEach((term) => {
console.log(this.filters);
});
}
}
}
}

最佳答案

使用 typescript 在调试时,请记住转译器可以重命名变量。在没有包含重命名的源映射的控制台中使用原始名称将显示未定义,即使原始值不是。确保在 watch 或控制台命令中使用转换后的名称。

关于javascript - 为什么 'this' 在调试器中未定义但可在 console.log 中打印?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51470986/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com