E.on('init'...)

Posted on
  • Hi all-
    I'm new user to the forum and Espruino.

    I couldn't find a way to edit code created for E.on('init'). Is there a way to do this?

    Or do I have to erase the entire handler with E.removeAllListeners('init')?

    Or use reset() ?

    Thanks for your help.

    -Neil

    (oh also couldn't find a way to change my username from the memorable "user70118." Wouldn't preserve my changes after hitting Save.)

  • Actually changing the function after you set it is difficult - you'd have to remove and re-add it. However if you do something like this:

    function foo() {
    }
    E.on('init', foo);
    

    Then each time you redefine foo it'll update the function. You can also just type edit(foo) on the left-hand side.

    That works for all kinds of things, but if you have an anonymous function it makes life much more difficult!

  • Thanks Gordon.

  • No problem - looks like you sorted your forum name out too? :)

  • Yes, someone had preemptively stolen my name but no error message appeared telling me so.

    So it appears onInit() is the simpler choice for startup routines and E.on('init'...) is for more esoteric needs.

  • Yes, E.on('init'...) is handy if you're copying and pasting code or writing libraries because if you do it twice, both bits of code get run. If you're actually fiddling with code using the left-hand side of the IDE then onInit can be easier - or you can do what I'd suggested above as well.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

E.on('init'...)

Posted by Avatar for .Neil @.Neil

Actions