|
|
|
|
|
by glenjamin
5316 days ago
|
|
I've been getting along fine with nothing but util.inherits from NodeJS. Are there any real advantages to the "set the prototype to this object" approach versus building it up by assigment? function Animal(legs) {
this.legs = legs;
}
Animal.prototype.speed = function() {
return legs * 10;
}
util.inherits(Dog, Animal);
function Dog(name) {
this.constructor.super_.call(this, 4);
this.name = name;
}
Dog.prototype.speed = function() {
// I don't disagree that more sugar here would be good
return this.constructor.super_.prototype.speed.call(this) * 2;
}
|
|
The problem I have is that the notion of a constructor function goes against prototypical OO.
In prototypical OO we just have objects and objects inherit from objects. there is no notion of a constructor function.
Also note that pd.make returns an object rather then a function.
It's simply a programming style I like, to think of my "class" object not as the constructor function but as the prototype object.
Not to mention that `x.prototype.foo = ...` is ugly.