简体   繁体   English

为什么MDN说“Function.prototype无法修改”?

[英]why MDN says that the “Function.prototype cannot be modified”?

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. MDN的Function.prototype页面中 ,无法修改Function.prototype “。但是当我在控制台中尝试以下代码时,它证明了我可以修改Function.prototype的现有属性,以及我们可以添加新属性。

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? 如果无法修改Function.prototype ,为什么我会看到这样的行为?

this question refers to the same problem. 这个问题指的是同样的问题。 But there what has been modified is the 'AclassName.prototype'. 但是那里被修改的是'AclassName.prototype'。 not the Function.prototype. 不是Function.prototype。

Function.prototype不是Function.prototype.call ,通常你可以做SomeConstructor.prototype = { ... } ,但你不能做Function.prototype = { ... }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM