Skip to content

Instantly share code, notes, and snippets.

@dgellow
Created January 30, 2014 11:11
Show Gist options
  • Save dgellow/8706534 to your computer and use it in GitHub Desktop.
Save dgellow/8706534 to your computer and use it in GitHub Desktop.
// Define a class
AwesomeClass = function () {
this.hello = function(param) {
console.log("[base method] ", param);
return param;
};
};
// Create an instance
awesome_object = new AwesomeClass();
// Extend the hello method by using a closure
awesome_object.hello = (function(){
var oldHello = new AwesomeClass().hello;
return function(param){
oldHello(param);
console.log("[closure] I'm here !");
return "[closure] param: " + param;
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment