setInterval in module not working #6212
Replies: 1 comment
-
Posted at 2020-01-26 by Robin Sat 2020.01.25 @raik, is the above code in one monolithic file, as the modules file, or is there a calling page? Is the desire to call a separate module page, or to learn how to develop a single file to develop the module code? It's possible that L21 needs to also pass 'freq' 'time' as arguments - e.g. the function parameter list isn't present in order to pass the argument values. Haven't tested, but thinking about it, I believe the above to be true. One could have included a console.log( freq, time ) statement within the L21 function to see if the values are 'undefined' or used the debugger. Google to the rescue! > *google:* passing function arguments using javascript setinterval site:w3schools.com
See example page bottom: Nothing to do with module development, language syntax. Posted at 2020-01-26 by @MaBecker This is about object reference. change this. to SOUND. in line 21.
or add ‘that’
Posted at 2020-01-26 by Robin Sun 2020.01.26 @MaBecker, (haven't tested) but wouldn't var 'that' L5 need to be global in order for L9 to see object 'that'? . . . or maybe (guessing) My belief was the (missing) argument syntax as shown in that link. Posted at 2020-01-26 by Raik
It's the piece of code from the editor I upload to experiment with modules. Later on this will be put to the file system as one file (that's the plan).
Well it's referring to the beep function, that only has two argument. So it should work, right?
Thanks for the hint: creating a new reference for this worked, though I'm not sure why? Is it because the module code runs in its own scope? And this is not referring to SOUND but rather to the main scope?
Posted at 2020-01-26 by AkosLukacs It's "just classic javascript Posted at 2020-01-27 by @gfwilliams Glad you got this sorted - this is one of the classic JavaScript pitfalls. The easiest way to think of it (I find) is that JS is dumb, and when you use
However arrow functions do remember the value of
Then it'd work :/ Posted at 2020-01-27 by Raik Thanks for the follow up! I kinda realized JS is "dumb", but expected a behavior similar to other language and got frustrated. I'll try out the arrow functions. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2020-01-25 by Raik
Hey all, I'm trying to write my first module for the pixl and I'm having difficulties with setInterval in the modules function. I was closely following the writing modules page.
I use the code below to develop in the WebIDE. The beep function works fine, so does the second function that just calls the beep function. But then the third function involves calling beep from a setInterval. And that is not working.
What am I doing wrong?
Beta Was this translation helpful? Give feedback.
All reactions