eventmodel
v2.0.2
Published
A bubblable event model
Downloads
4
Readme
EventModel
Demo
var EventModel = require('./eventmodel.js');
// Define a constructor A
var A = function() {};
// Create a instance from A
var a = new A();
// Bind 'test' event for 'a'
EventModel.on(a, 'test', function(e) {
console.log('a', e);
});
// Bind 'test' event for 'A.prototype'
EventModel.on(A.prototype, 'test', function(e) {
console.log('A.prototype', e);
e.stopImmediatePropagation();
});
// Bind 'test' event for 'A.prototype'
EventModel.on(A.prototype, 'test', function(e) {
console.log('A.prototype', e);
e.stopPropagation();
});
// Bind 'test' event for 'Object.prototype'
EventModel.on(Object.prototype, 'test', function(e) {
console.log('Object.prototype', e);
});
// Trigger the 'test' event on 'a',
// the event will bubbling along its prototype chain
EventModel.trigger(a, 'test');