Why does Function.x work after Function.prototype.x is declared?
As I understand it, the prototype property of a function is how you add methods / properties to all objects created from that function.
So when I try something like this
function Person(){}
Person.prototype.saySomething = function(){ alert( "hi there" ); }
Person.saySomething();
I am getting the error "Person.saySomething is not a function" which makes sense since Im not acting as an instance of a Person object.
But why does the code below work?
Function.prototype.sayHi = function(){ alert( "hi!" );}
Function.sayHi();
+3
source to share
1 answer