由于其中有this
,我自己无法手动调用回调函数。我不太擅长JS,这是我在JS中要做的唯一一件事。有一种简单的方法可以调用该函数吗?
}), i.createElement("div", {
id: "recaptcha-element-container",
className: t
}))
}, t.prototype.reset = function() {
null !== this.state.widgetId && window.grecaptcha && window.grecaptcha.reset(this.state.widgetId)
}, t.prototype.execute = function() {
null !== this.state.widgetId && window.grecaptcha && this.props.invisible && window.grecaptcha.execute(this.state.widgetId)
}, t.prototype.initRecaptcha = function() {
if (window.grecaptcha) {
var e = window.grecaptcha.render("recaptcha-element-container", {
sitekey: this.props.invisible ? c.p.config.invisibleCaptchaKey : c.p.config.captchaKey,
callback: this.onChange,
theme: "light",
type: "image",
size: this.props.invisible ? "invisible" : "normal",
tabindex: 0,
hl: this.props.languageCode,
badge: "bottomright",
"expired-callback": this.onExpired
});
this.setState({
widgetId: e
})
}
}, t
答案 0 :(得分:0)
正在被回调的功能,将其更改为窗口。为了指定什么是“ this”,您可以使用“ bind”中的任何一种,此处对此进行了全面描述:
Use of the JavaScript 'bind' method https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind
或者var this = that pattern
What does 'var that = this;' mean in JavaScript?
如果使用ECMA6及更高版本,则使用箭头功能将在“此”下为您提供预期的变量
What does arrow function '() => {}' mean in Javascript? What does "this" refer to in arrow functions in ES6?