吕君喜 406d880ac6 first | 3 年之前 | |
---|---|---|
.. | ||
lib | 3 年之前 | |
.jscsrc | 3 年之前 | |
.jshintrc | 3 年之前 | |
.npmignore | 3 年之前 | |
LICENSE | 3 年之前 | |
README.md | 3 年之前 | |
gulpfile.js | 3 年之前 | |
index.js | 3 年之前 | |
package.json | 3 年之前 |
Yet Another EventTarget Implementation.
The library exposes both the EventTarget interface and the Event interface.
$ npm install yaeti --save
var yaeti = require('yaeti');
// Custom class we want to make an EventTarget.
function Foo() {
// Make Foo an EventTarget.
yaeti.EventTarget.call(this);
}
// Create an instance.
var foo = new Foo();
function listener1() {
console.log('listener1');
}
function listener2() {
console.log('listener2');
}
foo.addEventListener('bar', listener1);
foo.addEventListener('bar', listener2);
foo.removeEventListener('bar', listener1);
var event = new yaeti.Event('bar');
foo.dispatchEvent(event);
// Output:
// => "listener2"
yaeti.EventTarget
interfaceImplementation of the EventTarget interface.
Make a custom class inherit from EventTarget
:
function Foo() {
yaeti.EventTarget.call(this);
}
EventTarget
:
javascript
yaeti.EventTarget.call(obj);
The interface implements the addEventListener
, removeEventListener
and dispatchEvent
methods as defined by the W3C.
listeners
read-only propertyReturns an object whose keys are configured event types (String) and whose values are an array of listeners (functions) for those event types.
yaeti.Event
interfaceImplementation of the Event interface.
NOTE: Just useful in Node (the browser already exposes the native Event
interface).
var event = new yaeti.Event('bar');