使用 lambda 时在 VS2013 中调试 "this" 的打字稿问题
Typescript issue with debugging "this" in VS2013 when using lambdas
我正在使用 "this" 的硬编码捕获转换一些 TypeScript 代码:
var _this = this;
var querySucceeded = function(data){
this.doSomething(data);
}
var test = this.executeQuery().then(function(data){
_this.querySucceeded(data);
});
使用 lambdas:
var querySucceeded = function(data){
this.doSomething(data);
}
var test = this.executeQuery().then((data) => {
this.querySucceeded(data);
});
TypeScript 将 JS 编译成类似于第一个代码块的东西,并且一切都在浏览器中运行良好。问题是在 Visual Studio 中调试时。当我在 lambda 之后检查 "this" 时,它显示 window 属性,而不是 class 上下文。
如果我直接在浏览器中调试,它会显示应有的本地上下文。这是一个已知的问题?可能是JS文件和TS文件的映射有问题?
我正在使用 VS2013 Update 4 和 TypeScript 1.4。
inspect "this" after the lambda, it shows the window properties, instead of the class context.
已知问题。这是因为名称未映射。您将需要检查“_this”
我正在使用 "this" 的硬编码捕获转换一些 TypeScript 代码:
var _this = this;
var querySucceeded = function(data){
this.doSomething(data);
}
var test = this.executeQuery().then(function(data){
_this.querySucceeded(data);
});
使用 lambdas:
var querySucceeded = function(data){
this.doSomething(data);
}
var test = this.executeQuery().then((data) => {
this.querySucceeded(data);
});
TypeScript 将 JS 编译成类似于第一个代码块的东西,并且一切都在浏览器中运行良好。问题是在 Visual Studio 中调试时。当我在 lambda 之后检查 "this" 时,它显示 window 属性,而不是 class 上下文。
如果我直接在浏览器中调试,它会显示应有的本地上下文。这是一个已知的问题?可能是JS文件和TS文件的映射有问题?
我正在使用 VS2013 Update 4 和 TypeScript 1.4。
inspect "this" after the lambda, it shows the window properties, instead of the class context.
已知问题。这是因为名称未映射。您将需要检查“_this”