add-events

2019-09-11

Simple library for decorating a prototypical class with events

addEvents()

Adds events to an existing pseudo-classical Javascript class.

NOTE: Overwrites the following variables within the prototype:

  • _eventTypes
  • _emit
  • on
  • once
  • removeAllListeners
  • removeAllOnceListeners
  • removeOnceListener
  • removeOnceListener

NOTE: Overwrites the following variables within the instance of a class

  • _onceListeners
  • _listeners

Loading

index.js is the source code and is compatible with browserify. index.umd.js was built as a standalone UMD package (without minification) so you can use it with AMD or a normal browser environment... The exported global is the name of the package within package.json (with hyphens etc removed).

Example

var MyClass = function() {
};

MyClass.prototype.doSomething = function() {
    return this._emit('doneit','a','b');
};

addEvents(MyClass,['doneit']);

var myClass = new MyClass();
myClass.on('doneit',function (a, b) {
    console.log('a = ' + a + ', b = ' + b);
});

myClass.doSomething();

Parameters

  • @param {Function} classFuncThe class to add events to.
  • @param {Array} eventsThe events you want the class to support.

Repository

https://github.com/forbesmyester/addEvents.git


上一篇:transition-state
下一篇:syncit-server
相关教程
关注微信

扫码加入 JavaScript 社区

相关文章

首次访问,需要验证
微信扫码,关注即可
(仅需验证一次)

欢迎加入 JavaScript 社区

号内回复关键字:

回到顶部