Inherit all methods of object (including "constructor"), but modify some of them.

Posted by Kirzilla on Stack Overflow See other posts from Stack Overflow or by Kirzilla
Published on 2010-05-14T10:55:09Z Indexed on 2010/05/14 11:04 UTC
Read the original article Hit count: 249

Filed under:
|

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.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery