I wrote it because I didn't know about these other utilities / tools.
And being able to do
var obj = protoObj <| { ... properties ... }
would be fantastic. If I that, and short function syntax then I'd be happy.We need an easy way to mixin/extend objects.
var obj = protoObj <| mixin({ ... properties ... }, mixinA);
We also need a solid way to create instances. object.create(obj);
obj.constructor();
is just too verbose. There is some talk around making `new` work with object exemplars which would be great.I promote code like
var Cat = Object.make(Animal, {
constructor: function() {
Animal.constructor.apply(this, arguments);
...
},
walk: function() {
Animal.walk.apply(this, arguments);
...
}
});
Now compare:- Animal.walk.apply(this, arguments);
- this.super.apply(this, arguments);
- this.super.walk.apply(this, arguments);
Using super doesn't fix verbosity, it only fixes hard coupling of Child class name to Super class name.
For the complexities, edge cases and performance penalties a super implementation gives, it's simply not worth fixing this hard coupling.
If you know of a super implementation that _just works_ please [Leave an answer on StackOverflow](http://stackoverflow.com/questions/8032566/emulate-super-in-...)
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;
}Beyond the need for calling the constructor (which I'm currently viewing it as an unnecessary hidrance [objects are already initialized]), Object.getPrototypeOf may provide a way out - but maybe not the way you intended. Have you considered it?