The problem with the function scope object #7204
Replies: 1 comment
-
Posted at 2017-12-05 by @gfwilliams Which firmware version are you running this on, and on what device? I just ran this on the latest builds and it works fine. However: If you put this in the right-hand side of the web IDE you get loads of errors. I'd fix those first. Specifically what do you intend to do with Posted at 2017-12-05 by Konkery Thank you for such a quick response ! Posted at 2017-12-05 by Konkery In the code there are no syntax errors it builds and runs fine, below part of code:
Posted at 2017-12-05 by @gfwilliams Moving this to 'other boards' - IskraJS isn't an official board - they're just using the Open Source Espruino firmware. I've tried to run your code even on a 1v92 version of Espruino and it works (without the Exception) - perhaps you could contact Amperka to see if they can help you out. Posted at 2017-12-05 by Konkery Thanks again ! Posted at 2017-12-10 by Konkery The problem is solved. Loss of context occurred in one of the plugins. The firmware of the Amperka code executes correctly. Posted at 2017-12-11 by @gfwilliams Great! By 'loss of context', you mean you called it in a Posted at 2017-12-11 by Konkery Yes, "this" was lost in one of setTimeout Posted at 2017-12-11 by @allObjects JavaScript provides you with standard means to ensure the desired context:
As you know, you can defined the function as a named function outside of
There are many options and combinations there of you can chose from for the optimal use in your situation. For the alternative 'this', I use the Posted at 2017-12-11 by PaddeK Or.. if the contextObject you need is the outer scope just use a arrow function as setTimeout callback and be done with it. Other public choices for the this alter ego are Posted at 2017-12-12 by Konkery Thank you all for the advice !
Posted at 2017-12-13 by @allObjects ...? ...do not exactly get what above code should proof or disproof...
Should run in Espruino and provide output in the console like that:
...you can also just open the debugger of (chrome) browser (with 'right-click' Inspect) and paste the code into the console... :) As the output shows, Alf - objAlf - and Ann - objAnn- know still about their names, their time interval to show up, and who commanded them: Ben and Bob. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2017-12-05 by Konkery
There is an object created via new:
Help !
I tried various options with this, call and bind, nothing helped. How to organize a call to "this.Obj_2.func_Class_1()" ?
Beta Was this translation helpful? Give feedback.
All reactions