【发布时间】:2017-03-14 04:54:33
【问题描述】:
一旦调用回调,我试图将在类开头声明的变量(布尔值)设置为 true,但我不断收到 TypeScript 错误。
这是错误:
TypeError: Cannot set property 'nonReceived' of undefined
这是我的代码:
finalizeToken(){
braintree.setup(JSON.parse(this.finalToken), 'dropin', {
container: 'dropin-container',
defaultFirst: true,
form: 'checkout-form',
onPaymentMethodReceived: function (obj) {
this.nonReceived = true;
localStorage.setItem('nonce', obj.nonce);
}
});
}
brintree-setup 连接到 Braintree Payments,并等待用户支付信息。他们提交表单后,我需要将变量“this.nonReceived”设置为 true。
【问题讨论】:
-
绑定
this或使用箭头函数 -
如何绑定这个?
-
见here
-
在我的示例中会是什么样子?绑定函数会去哪里?
标签: javascript typescript braintree