Created
January 30, 2014 11:11
-
-
Save dgellow/8706534 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
// 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