Then, I suppose, the fuller question is, "How are those considerations affected when the Javascript engine is known (on a per popular engine basis)."
The reason I feel I need to ask "community" is because those like Strongloop who create things like Node.js, also write code like util.inherits, a function inside which, instead of: TheConstructorFunction.prototype.constructor = TheConstructorFunction
they create a property definition which itself has 4 properties being set:
ctor.prototype = Object.create(superCtor.prototype, {
constructor: {
value: ctor,
enumerable: false,
writable: true,
configurable: true
}
});
This seems inefficient to me, but then, I've only been striving to write better Javascript for 3 years as opposed to authors of code like this. Is there an explanation for why this is or isn't efficient?
One answer says that util.inherits is not inefficient because subclass operations are rare. But considering some libraries deal with hundreds and thousands of subclass operations happening between build to test result observation, if Node.js internally uses util.inherits then that affects development time of its consumers. I think, on this level efficiency does matter and I hope util.inherits is not being used internally. I don't even understand the purpose of util.inherits. Why have it at all? I think it promotes compounding inefficiency. require('util').inherits(C1,C2);
is almost synonymous and likely slower than C1.prototype=Object.create(C2.prototype); C1.prototype.constructor=C1;
If it is just meant to lure consumers, I'm cool with that. My concern is if these pros are using that function internally since larger libraries will be depending on Node.js' efficiency. As for making .constructor
non-enumerable... I think the case where its "enumerability" matters is rare and should be left up to the consumer, but if internal operations are depending on util.inherits, this isn't really being left up to the consumer.