add-events

2019-09-11 admin

add-events是什么

什么是add-events,Simple library for decorating a prototypical class with events

add-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

Source Code

Source code is prepared using Browserify which is also compatible with Node.JS. There is a UMD bundle which can be used with AMD or a vanilla browser (where it will export a global called called addEvents.

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} classFunc The class to add events to.
  • @param {Array} events The events you want the class to support.

本站文章除注明转载外,均为本站原创或编译。欢迎任何形式的转载,但请务必注明出处。

转载请注明:文章转载自 JavaScript中文网 [https://www.javascriptcn.com]

本文地址:https://www.javascriptcn.com/read-74852.html

文章标题:add-events

回到顶部