How to access 'this' inside a callback function in Typescript?
<p>I am trying to set a variable declared at the beginning of the class (a boolean) to true once a callback is called, but I keep getting a TypeScript erorr.</p>

<p>Here is the error:</p>

<pre><code>TypeError: Cannot set property 'nonReceived' of undefined
</code></pre>

<p>Here is my code:</p>

<pre><code>  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);
    }
  });  
}
</code></pre>

<p>The brintree-setup connect to Braintree Payments, and awaits user payment info. Once they submit the form, I need the variable "this.nonReceived" to be set to true.</p>