I want to know if extending a Function's prototype dynamically is a bad practice. I'm considering to do this using a static method that receives the property name and the function to add to the prototype.
Is that a bad practice?
function Test() {
this.condition = false;
}
Test.extend = function(id, task) {
this.prototype[id] = function() {
return task.apply(this, arguments);
};
};
task
instead ofthis.task
, and should be shortened tothis.prototype[id] = task;
– Parallax.apply
. – ErectFunction.prototype.apply
... – Shameful.apply
necessary. Generally speaking, as a rule of thumb, inheritance is bad. Inheritance that is not visible by glancing at the source code is worse. And prototypal inheritance is still inheritance. – Shameful