Create new emitter
var emitter = Emitter.create();
Trigger the specified event. Any additional parameters will be passed to the callback.
emitter.emit("ready");
emitter.emit("ready", arg1, arg2, argN);
Attach a new event handler.
emitter.on("ready", callback);
emitter.on("ready", callback, this);
Detach a specific event handler. If no callback
is
provided, then all event handlers will be removed.
emitter.off("ready", callback);
emitter.off("ready");
Return a copy of all listeners for a given event
name.
If event
doesn't exist, then an empty array will be
returned instead.
emitter.listeners();
Attach a new event handler that will be executed only once.
emitter.once("ready", callback);
emitter.once("ready", callback, this);
You can extend objects.
var object = {};
Emitter.extend(object);
object.on("ready", callback);
object.emit("ready");
Install jasmine-node
with npm install jasmine-node -g
and
run tests with jasmine-node emitter.spec.js
.