Inherit all methods of object (including "constructor"), but modify some of them.
- by Kirzilla
Hello,
Let's imagine that we have object Animal
$.Animal = function(options) {
this.defaults = { name : null }
this.options = $.extend(this.defaults, options);
}
$.Animal.prototype.saySomething = function() {
alert("I'm animal!");
}
Now I'd like to create Cat object. It is absolutely similar to $.Annimal, but method saySomething() will look like this one...
$.Cat.prototype.saySomething = function() {
alert("I'm cat!");
}
How can I inherit from Animal to create new object Cat and redefine saySomething() method?
Thank you.