Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why MDN says that the "Function.prototype cannot be modified"?

Tags:

javascript

In Function.prototype page in MDN says that the Function.prototype cannot be modified". But when I tried the following code in the console, it proved me that you can modify the existing properties of the Function.prototype, as well as we can add new properties to it.

Function.prototype.call = function(context) {
  console.log("call() fn has been modified");
};

var f = function() {
  //do something..
};

f.call(this);

and it shows the following as the result in the console.

call() fn has been modified

If the Function.prototype cannot be modified, why I am seeing such a behavior?

this question refers to the same problem. But there what has been modified is the 'AclassName.prototype'. not the Function.prototype.

like image 940
Ishara Jayaweera Avatar asked Mar 19 '26 08:03

Ishara Jayaweera


1 Answers

Function.prototype is not Function.prototype.call, normally you can do SomeConstructor.prototype = { ... }, but you cannot do Function.prototype = { ... }.

like image 160
Madara's Ghost Avatar answered Mar 21 '26 22:03

Madara's Ghost



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!