Created
February 27, 2010 18:53
-
-
Save mneedham/316879 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
Playing with some code to understand overriding. | |
This works: | |
function Foo() {} | |
Foo.prototype = { | |
bar : function() { | |
console.log("original bar"); | |
} | |
} | |
var originalBar = Foo.prototype.bar; | |
Foo.prototype = { | |
bar : function() { | |
originalBar.apply(this, arguments); | |
console.log("new bar"); | |
} | |
} | |
new Foo().bar(); | |
> original bar | |
> new bar | |
But I don't want 'originalBar' to be exposed so I try to use the proxy pattern: | |
(function() { | |
var originalBar = Foo.prototype.bar; | |
Foo.prototype = { | |
bar : function() { | |
originalBar.apply(this, arguments); | |
console.log("new bar"); | |
} | |
} | |
})(); | |
new Foo().bar(); | |
> TypeError: ({bar:(function () {console.log("original bar");})}) is not a function | |
Any ideas? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment