EventEmitter for WebBrowser
- event_emitter.js
- event_emitter.min.js (compressed)
load
<script src="event_emitter.js"></script>
apply
var User = function(){
new EventEmitter().apply(this);
this.name = '';
};
regist event listener
var user = new User();
user.name = 'shokai';
user.on('go', function(data.place){
alert(user.name+' -> '+data.place);
});
call event
user.emit('go', {place: 'mountain'}); // "shokai -> mountain"
regist event using "once"
user.once('eat', function(data){
alert(user.name+' -> eat '+data.what+' at '+data.where);
});
call
user.emit('eat', {what: 'BEEF', where: 'zanmai'}); // "shokai -> eat BEEF at zanmai"
user.emit('eat', {what: 'Ramen', where: 'marutomo'}); // do not call. call only first time.
remove listener
user.removeListener('eat');
user.removeListener(id);
catch all events
user.on('*', function(event_name, data){
console.log(event_name + ' was called');
console.log(data);
});
% npm install -g nodeunit
% make
edit "HEADER.txt"
% npm install -g uglify-js
% make build
=> event_emitter.js and event_emitter.min.js
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request