Slide 40
Slide 40 text
Inheritance Ctor
// Inherits from Animal
var Cat = function(name, color) {
Animal.call(this, name);
this.color = color;
};
util.inherits(Cat, Animal);
Cat.prototype.getColor = function() {
return this.color;
};
1. First thing you do in your Ctor is to call your Parent's
Ctor using your own, new, context (scope)
2. Then, right after the Ctor, invoke the inherits function
3. Afterwards define your methods. Can even overwrite
the parent's
1
3
2