-1

I have trouble calling the callback function manually by myself because of the this in it. I'm not really good at JS and that is the only thing I have to do in JS. Is there an easy way to call that function?

}), 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
Donald Duck
  • 8,409
  • 22
  • 75
  • 99
  • When using snippets, please paste in the correct pane. Also preferable to post a [mcve] – mplungjan Dec 16 '18 at 17:37
  • Which callback in particular are you talking about? – Bergi Dec 16 '18 at 17:40
  • i don't think we can call the callback explicitly because their execution totally depends upon some other conditions before it. – jalil Dec 16 '18 at 17:44
  • I think i want to call "callback: this.onChange" basically i want to verify the users recaptcha input @Bergi – Joey Seller Dec 16 '18 at 18:00
  • It's unclear where `this.onChange` comes from, but probably you can solve this using any of the approaches in the duplicate – Bergi Dec 16 '18 at 18:04

1 Answers1

0

Functions that are being called back, change this to be a window. In order to specify what a "this" is you might use either "bind" which is comprehensively described here:

Use of the JavaScript 'bind' method https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind

Or var this = that pattern

What does 'var that = this;' mean in JavaScript?

If using ECMA6 and above then using arrow function will provide you with expected variable under "this"

What does arrow function '() => {}' mean in Javascript? What does "this" refer to in arrow functions in ES6?

Cezary
  • 11
  • 1
  • 2