学习一些 TypeScript。试图使这段代码工作:
...
ocrText: string;
...
foo() {
Tesseract.recognize(<Tesseract.ImageLike>document.getElementById('image'))
.then(function(result) {
console.log(result);
this.ocrText = result.text;
});
}
收到此错误:Uncaught TypeError: Cannot set property 'ocrText' of undefined
控制台日志确实显示了对象属性和值。
如何从“结果”对象中提取“文本”属性的本地值到全局范围?