Skip to content

Implementation of W3C DOM Events as a JavaScript component.

Notifications You must be signed in to change notification settings

graouts/dom-events

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dom-events

Implementation of W3C DOM Events as a JavaScript component.

Installation

Install with component(1):

$ component install graouts/dom-events

Usage

You can create an EventTarget instance and use it to register event listeners and dispatch events:

var DOM = require("dom-events");
var eventTarget = new DOM.EvenTarget;

// Register an event listener that is a simple callback
eventTarget.addEventListener("foo", function(event) {
    // …
});

// … or call a method in the scope of some object
eventTarget.addEventListener("foo", methodName, someObject);

// … or let that object implement the handleEvent(event) method and pass the object as the listener
eventTarget.addEventListener("foo", someObject);

// Dispatch an event!
eventTarget.dispatchEvent(new DOM.Event("foo"));

You can also use a mixin style and have any class or object become an EventTarget:

var DOM = require("dom-events");

function Custom() {
    DOM.EventTarget(this);
}

Custom.prototype = {
    constructor: Custom,
    __proto__: DOM.EventTarget.prototype
}

About

Implementation of W3C DOM Events as a JavaScript component.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published