SOURCE

function Callbacks() {
  var list = [];
  var self;
  self = {
    add: function(fn) {
      list.push(fn)
    },
    fire: function(args) {
      list.forEach(function(fn) {
        fn(args);
      })
    }
  }
  return self;
}

function fn1(val) {
  console.info('fn1 says:' + val);
}
        
function fn2(val) {
  console.info('fn2 says:' + val);
}
        
var cbs = Callbacks();
cbs.add(fn1);
cbs.add(fn2);
cbs.fire('foo');
cbs.fire('bar');
console 命令行工具 X clear

                    
>
console