JavaScript中的非法调用

JavaScript中的非法调用,javascript,typeerror,Javascript,Typeerror,我不知道为什么会这样,我认为这是不可能的,或者至少是非常困难的 代码如下: function clonar (obj) { var clonado = obj; return obj; } var getter = clonar(document.getElementById); var getting = clonar(getter) document.__proto__.getElementById = function (element) {

我不知道为什么会这样,我认为这是不可能的,或者至少是非常困难的

代码如下:

function clonar (obj) {

    var clonado = obj;
        return obj;

} 

var getter  = clonar(document.getElementById);

var getting = clonar(getter)

document.__proto__.getElementById = function (element) {

        return getting(element);

};

document.getElementById('wz-notification');
当执行这个脚本时,我得到一个
TypeError:invalical invocation
。我不知道为什么会失败,也不知道是什么原因导致了这个错误。至少,在Chrome中,控制台没有告诉我什么是失败的。我认为问题在于在一个新函数中从
getElementById
调用本机函数代码,它会覆盖本机函数
getElementById


谢谢你的预付款

不管这种方法还有其他问题,我希望您认识到
getter
get
document.getElementById
都指向同一个函数(在它被覆盖之前)?(例如,
console.log(getter==get,get==document.getElementById);
=>
true
)。您基本上是在编写
var getter=document.getElementById,get=getter
getElementById()
想知道调用它的文档。您的
获取
是正确的功能,但与
文档
分离。您需要执行
返回get.call(文档、元素)
。但是为什么不直接返回document.getElementById(element)?作为旁注:这里不需要访问
\uuuuu proto\uuuu
属性,这在任何地方都不受支持。您可以改用构造函数的
prototype
属性:
Document.prototype.getElementById