super-event

0.0.3 • Public • Published

super-event

event给予对象绑定和触发自定义事件的能力

Install

npm install super-event

Use

var Event = require('super-event');
var e = new Event();

Inherit

var Event = require('super-event');
function Sub(){
    Event.call(this);
}


Sub.prototype = new Event(); //或 Sub.prototype = Object.create(Event.prototype);

Sub.prototype.otherMethods = function(){};

Api

  1. on object.on(event, callback, [context])
    绑定事件,多个事件用空格隔开
  2. off object.off([event], [callback], [context])
    卸载事件,多个事件用空格隔开
  3. trigger object.trigger(event, [*args])
    触发事件,多个事件用空格隔开
  4. once object.once(event, callback, [context])
    绑定一个事件
  5. pause object.pause(event, callback, [context])
    暂停事件,多个事件用空格隔开
  6. resume object.resume(event, callback, [context])
    恢复事件,多个事件用空格隔开

Exaple

//on,once,off,pause,resume
//用法类似,context函数执行上下文,默认是当前对象
//在new Event([cxt]),也可以统一指定上下文

var Event = require('super-event'); var e = new Event();

e.on('touch:start', function (args) { console.log('touch:start',args); })

e.on('touch:move', function (args) { console.log('touch:start',args); },e)

e.on('touch:end touch:cancle', function (args) { console.log('touch:end',args); })

e.trigger('touch:start','abc');

e.off('touch:cancle');

Readme

Keywords

Package Sidebar

Install

npm i super-event

Weekly Downloads

0

Version

0.0.3

License

MIT

Last publish

Collaborators

  • wanglei8381