Correct syntax needed for bind() on 'this' object using class #1189
Replies: 5 comments
-
Posted at 2018-09-18 by @allObjects The intended use is:
...use of the bound method can now be used as plain function in all places where only a function can be passed:
in a simplified and fast form:
in replacement of anonymous function:
Bind is nothing else than the above, just a bit faster, smarter, and leaner (less resources). Often, you will see the pattern of a
There was a time that this was the only way to be done. But a while now, setTimeout() (and setInterval() ?) allow passing of arguments that are resolved at setup of setTimeout() (and setInterval()?):
Imagine a second method
that will do something in a timeout or interval involving the
Take also a look at Here some fun to play Math Jeopardy with:
;-) I added the JS modulo or modulus % with 10 so the numbers stay within 0..9 (or % 6 for 0..5) for players -like me when it it's late - used to pocket calculator or phone only and not anymore to learn square up to 59 and all the tricks that go with it like: 25 square is 2*(2+1) and appended 25... goes for a the one with 5 at the end... 125 square is 12*13 + "25"... Espruino will tell you in the console in an instant... this is for square... so for cubic I should simplify even more... also for me... (it's already late).
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2018-09-18 by @gfwilliams I think as usual @allObjects has done an awesome job of answering the question about But looking at the code above, there are a few big issues that I thought it might help if I point out in-line:
I'm not sure any of these problems you're having would be fixed by how you use I think what you intended to do was probably:
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2018-09-18 by Robin Tue 2018.09.18 Thanks both for the quick and attentive responses. I thought I'd found the culprit. I mistakenly used
But when I run that
This is why I originally used the syntax |
Beta Was this translation helpful? Give feedback.
-
Posted at 2018-09-19 by @allObjects ...it looks like hat you have some left-overs in your Espruino... g is nowhere defined in that snipped, so I expect it came from previous post... but it also could come from some internal that the interpreter looks at, does not find it a bindable, but thinks it is a number. Doing things in the console without wiping every thing out, creates a lot of confusion. Again, I feel that Espruino is still playing tricks on you, @robin... Espruino is a living object,... similar to the DOM of or in a Browser. Most operation on it leave some (big Bear claw) prints behind... to haunt later... Halloween is about to come... So we should get some Espruino driven flashy wearables... what about a contest, @gordon? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2018-09-19 by @gfwilliams could be a nice idea - I'll have a think! I've been meaning to try some contests - for example I reckon now tweets are 280 chars you could do some really interesting things in hardware JS :) @robin as @allObjects says, each command you write on the left-hand side after you upload is changing the state of the interpreter. If you thought that each command you typed was executed on a fresh instance of your code it could actually be a really big cause of the problems you're having. Please check out some of the comments below - they might help.
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2018-09-18 by Robin
Mon 2018.09.17
Goal:
The MDN example works using the Json object notation form. When I attempt to use a class however, I'm greeted with either function not found or undefined
The constructor seems to ignore the initial default assignment - why not -1
Then if I use a setter, then it's not clear if the constructor initialized correctly
If I use the () notation - so which is correct, without the () or using the () ?
How can function getX() not be found when it is clearly defined?
Following the example from MDN, and applying to this class
VERSION 1v99
Attachments:
Beta Was this translation helpful? Give feedback.
All reactions