• Based on the tip from @d3nd3-o0 I changed the example in message #1 to:

    var eventEmitter = new Object();
    
    //Create an event handler:
    var myEventHandler = function () {
      console.log('I hear a scream!');
    };
    
    //Assign the event handler to an event:
    eventEmitter.on('scream', myEventHandler);
    
    //Fire the 'scream' event:
    eventEmitter.emit('scream');
    

    The result:
    I hear a scream!

    So that works!

    So, there is no need in Espruino to require an events module, instead you just create an object, and use that as event emitter.

    Thanks to @d3nd3-o0 for guiding me in the right direction!

About

Avatar for gerardwr @gerardwr started