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!
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Based on the tip from @d3nd3-o0 I changed the example in message #1 to:
The result:
I hear a scream!
So that works!
So, there is no need in Espruino to
require
anevents
module, instead you just create anobject
, and use that asevent emitter
.Thanks to @d3nd3-o0 for guiding me in the right direction!