是否可以使Object.prototype为空?

时间:2018-05-06 05:55:12

标签: javascript

我正在检查一些JS库代码,并且知道他们正在使用原型函数来自主要的对象,如 for (int i = 0; i < f; i++) System.out.println(ff[i]); (这里是一个对象)。那么是否可以在主要对象原型中分配Object.prototype.toString.call(a, this),例如null

1 个答案:

答案 0 :(得分:5)

Object.prototype是not writable。所以不行。事实上,没有任何内置原型是可写的。

你可以在这里试试:

console.log(typeof Object.prototype.toString); //"function"
Object.prototype = null;
console.log(typeof Object.prototype.toString); //not nullified - still "function"

console.log(typeof String.prototype.substring); //"function"
String.prototype = null;
console.log(typeof String.prototype.substring); //same

相关问题