We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
写一个对象 Bus,提供 on、emit 方法,on 实现监听,emit 实现触发,使用方式如下:
Bus
on
emit
Bus.on('event', function(data) { console.log(data) }) Bus.on('hi', function(data) { console.log(data) }) Bus.emit('event', {name: 'hello'}) Bus.emit('hi', {to: 'hunger'}) Bus.emit('hi', {to: 'valley'})
The text was updated successfully, but these errors were encountered:
let Bus = { // 使用event存储 Bus.on 的函数 event:{}, on:function(name,fn){ this.event[name] = fn }, emit:function(name,param){ this.event[name](param) } } Bus.on('event', function(data) { console.log(data) }) Bus.on('hi', function(data) { console.log(data) }) Bus.emit('event', {name: 'hello'}) Bus.emit('hi', {to: 'hunger'}) Bus.emit('hi', {to: 'valley'})
Sorry, something went wrong.
No branches or pull requests
写一个对象
Bus
,提供on
、emit
方法,on
实现监听,emit
实现触发,使用方式如下:The text was updated successfully, but these errors were encountered: