Created
June 21, 2016 17:57
-
-
Save stevenhao/83a834a7a22357b3437c73705a9bf2be to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print = console.log.bind(console); | |
err = console.error.bind(console); | |
function Dispatcher(name) { | |
function evtname(evt) { | |
return name + '.' + evt; | |
} | |
this.fire = function() { | |
evt = arguments[0]; | |
args = Array.prototype.slice.call(arguments, 1); | |
print.apply(console, ['firing', evtname(evt)+'('].concat(args).concat(')')); | |
$(document).trigger(evtname(evt), args); | |
} | |
this.listen = function(evt, callback) { | |
$(document).on(evtname(evt), function() { | |
callback.apply(this, Array.prototype.slice.call(arguments, 1)); | |
}); | |
} | |
} | |
M = new Dispatcher('M'); | |
V = new Dispatcher('V'); | |
$(function() { | |
Controller.start(); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment