Slide 38
Slide 38 text
Inheritance Ctor
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 we define our own methods and can even
overwrite the parent's
1
3
2