sequencing - configure, require(), initializing w/ onInit() and save() ...and bind() #474
Replies: 5 comments
-
Posted at 2015-11-02 by @allObjects An interesting turn takes this code - which - in a nutshell:
The output for the bound this produced with
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-11-02 by @gfwilliams Did you try this on desktop JavaScript? I just did with jsbin and it behaves exactly the same way in your first example. I think your problem is that you're not using So:
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-11-02 by @allObjects Ic - ...dddooooh.. :(). Therefore, the proper usage is (see line
And the output confirms that
Alternative - to avoid the awkward redefinition / reassignment - and for the case of multiple intances, it is better to adjust line
Drawback of this cleaner solution is the recreation of the bound function everytime... To avoid this, the bound function could be assigned as separate
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-11-03 by alexanderbrevig I could not help but to read your post with s/obj/crystal/g and found it kind of funny. Got it. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-11-03 by @allObjects ...yep, the abstraction and reduction to the minimum made it look like this... Actual code is this code below and hardware as attached pic... and it works pretty neat... it is a way to get out of callback hell and reduce it to sequence hell... I do not know what is better... global controller
gCtl is global Control for initializers... and the discussed line is line # The global controller for initializations is used to separate configuration from initialization - first - and - second - to have reliable constructs to call from Latter allowed to put calls like commands into a fifo and execution has to await an ack before moving on to the next command... almost the same as making a callback. Log output of above initializer produced in line
In case of failed, above - very lean - initializer control has no retries or error handling (vs the not so lean Tasker has).Attachments: |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-11-02 by @allObjects
NOTE: Conversation title was EDITED: Read the first three posts - #1..#3 - under the subtitle bind() not working because it was triggered by trying to make
require()
and.connect()
and all kinds of initializers to work correctly after save() and power recycle in a standalone operation using a sequencer as presented in post #6.In some initialization sequencing I had the construct that simplified to the essentials looks like this:
Above code uploaded to Espruino (PICO) and
onInit()
invoked in the console produces the following output:First invocation obviously works - because it is a standard invocation - but second - in
set Timeout(...
in line10
- fails.Afaiu
fnctn.bind(ctx)
binds thectx
object to the functionfnctn
so thatthis
in function is resolved toctx
context object. As examples shows, Espruino js does not.Changing line
10
todoes not help.
Changing
onInit() {...
toshows that
.bind()
is not working.I could reason that it would not work with multiple objects created with a constructor and
meth
had been defined on the prototype, and then bound to one of the created objects, and if multiple times bound, the last would win (...but it is not or neither,... see next post...).Beta Was this translation helpful? Give feedback.
All reactions