TalAter / annyang

💬 Speech recognition for your site
https://www.talater.com/annyang/
MIT License
6.63k stars 1.05k forks source link

"This " keyword issue. #424

Closed rnkpareek closed 4 years ago

rnkpareek commented 4 years ago

I want to fill my form using this ,But when iam setting the command and function. The function is being called bu unable to read the "this" keyword and gives error.

Uncaught TypeError: Cannot read property 'registerForm' of undefined at onSubmit (app.component.ts:111) at P (annyang.min.js:12) at SpeechRecognition.a.onresult (annyang.min.js:12)

TalAter commented 4 years ago

This is most likely not an annyang specific issue but simply the way JavaScript functions behave. You are passing a function and then having it called from a different context so the this is different.

I would suggest looking at something like bind()

The bind() method creates a new function that, when called, has its this keyword set to the provided value, with a given sequence of arguments preceding any provided when the new function is called.