1.1.3 • Published 6 years ago

eventobj v1.1.3

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

eventObject

Usage is basically the same as for Object.create(). With some added features.

const eventObject = require("eventobj");

let myEventObject = eventObject.create(prototypeObject[, propertiesObject]);

methods

The new eventObject will get a number of new methods.

on

Adds an eventlistener to the object.

Usage:

myEventObject.on("myEvent", function () {
  // 'this' will be bound the 'myEventObject' object
});

off

Removes an eventlistener to the object. To remove a listener it has to be a function expression.

Usage:

myEventObject.off("myEvent", '[function expression]');

trigger

Triggers an eventlistener. Takes an, optional, second "context" (object) argument that 'this' will be bound to.

Usage:

myEventObject.trigger("myEvent"[, contextObject]);

addChild

Adds a childnode the the object. The child object will also be an eventObject. This will make DOM-like bubbling possible. When an event is triggered on the childObject it will bubble to its parent.

The childObject will also get a "bubblesTo" array that can be used for "non hierarchyal" bubbling.

Usage:

myEventObject.addChild("newChildName", newChildObject);

listeners

Returns an array containg the listeners for the specified event. If there is no listeneners it returns an empty array.

Usage:

let listeners = myEventObject.listeners("myEvent");
1.1.3

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.1

6 years ago