2.0.2 • Published 9 years ago

eventmodel v2.0.2

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

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');
2.0.2

9 years ago

2.0.1

9 years ago