Skip to content

Instantly share code, notes, and snippets.

@n1k0
Created December 24, 2011 08:00
Show Gist options
  • Save n1k0/1516755 to your computer and use it in GitHub Desktop.
Save n1k0/1516755 to your computer and use it in GitHub Desktop.
`this` is magic
function Foo() {
var self = this;
this.hello = function(fn) {
fn.apply(self, Array.prototype.splice.call(arguments, 1));
};
this.bar = function(what) {
console.log('ok:' + what);
};
}
var foo = new Foo();
foo.hello(function(plop) {
this.bar(plop); // "ok:booh"
}, 'booh');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment