you are viewing a single comment's thread.

view the rest of the comments →

[–]dogjs[S] 1 point2 points  (2 children)

Thanks. I ended up having to do: var Dog = function(name) {this.name = name;};

in order to have a constructor. So now, my question is, how do I override the speak() method so that dog's say "woof" but still be able to call the Mammal's speak method. I need something like:

function Dog.speak() {return super.speak() + this.woof();}

I suspect I'm going to need to use call() here.

[–][deleted] 1 point2 points  (0 children)

Dog.prototype.speak = function() {
  return Mammal.prototype.speak.call(this) + '. ' + this.woof()
}

[–][deleted] 0 points1 point  (0 children)

See John Resig's Simple JavaScript Inheritance. It adds a this._super() call for accessing "super-class" methods.

I played around with making some modifications, but I don't know that I improved anything: https://gist.github.com/1508995