Skip to content

Instantly share code, notes, and snippets.

@iskugor
Created August 21, 2012 08:06
Show Gist options
  • Save iskugor/3413357 to your computer and use it in GitHub Desktop.
Save iskugor/3413357 to your computer and use it in GitHub Desktop.
var callback = function() {
//do something
}
...
var someObject = new SomeObjectConstructor();
someObject.on('click', callback);
...
function SomeObjectConstructor() {}
SomeObjectConstructor.prototype.on = function(type, callback, thisValue) {
var _this = thisValue || this;
var wrappedCallback = function() {
callback.call(_this);
};
//assume "this._wrappedObject" exists and that it has "addEventListener" method that takes 2 arguments
this._wrappedObject.addEventListener(type, wrappedCallback);
}
SomeObjectConstructor.prototype.off = function(type, callback) {
???
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment