is it possible to extend the function-prototype of "myfunction" - without a manipulation of Function.prototype - in the same way it is possible to extend the object-prototype (myfunction.prototype.method = function(){}
)?
Kind regards
is it possible to extend the function-prototype of "myfunction" - without a manipulation of Function.prototype - in the same way it is possible to extend the object-prototype (myfunction.prototype.method = function(){}
)?
Kind regards
Yes, we can extend function prototype. Every javascript function inherits from built in Javascript Function object, and therefore are type of Function object. W3schools example:
function Person(first, last, age, eyecolor) {
this.firstName = first;
this.lastName = last;
this.age = age;
this.eyeColor = eyecolor;
}
Person.prototype.name = function() {
return this.firstName + " " + this.lastName;
};
W3schools link MDN Link Function
Note: Never modify default prototype of any javascript object.
Regarding native functionality, JavaScript has prototype
into the depths of its core. Although not clear, you could use extension onto Native Prototypes, including, among others, the Function objects.
I would suggest being careful of doing so though, as this might lead to unexpected behaviors and side effects - as on every change of "default", native functionality, as this can be a bad idea.