var events = require('events');
var eventEmitter = new events.EventEmitter();
//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');
But this results in the error:
I read in the Espruino documentation here http://www.espruino.com/Reference#l_Object_emit about Object.emit and Object.on but can not find any reference or example on how to setup an eventEmitter in Espruino.
I'm rather new to Espruino/Javascript so maybe there's an obvious answer. Can someone point 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.
Hi,
I would like to create my own event handlers similar like the Bangle event handlers, f.i. the "step" handler.
Tried this example from https://www.w3schools.com/nodejs/nodejs_events.asp
But this results in the error:
I read in the Espruino documentation here http://www.espruino.com/Reference#l_Object_emit about Object.emit and Object.on but can not find any reference or example on how to setup an eventEmitter in Espruino.
I'm rather new to Espruino/Javascript so maybe there's an obvious answer. Can someone point me in the right direction?