I'm learning to use javascript's prototype feature (not the library). I thought I could replace an object's method by using MyObject.prototype.myFunction = function () { ... }. Apparently this doesn't work.
The code below defines an object, and replaces its function using prototype. Run it in your browser, the console still shows the original output.
<script type="text/javascript">
function TestObject() {
this.testFunction = function() {
console.log("Original function output");
}
}
// This should replace the method defined in the object.
TestObject.prototype.testFunction = function() {
console.log("YOU GOT CHANGED");
}
var HelloWorld = new TestObject();
HellowWorld.testFunction(); // Should output "YOU GOT CHANGED"
</script>