我想知道该函数存储在哪里?
我这么问是因为我尝试在 console.dir(document) 中查找它,但找不到其中的任何方法?
我对此很好奇。谢谢!
最佳答案
该方法作为 DocumentPrototype
对象的一部分公开,可在 window.Document.prototype
下访问:
window.document
实例仅从 Document
类继承。
console.log( Document.prototype.getElementById );
Document.prototype.getElementById = (val) => 'gotcha ' + val;
console.log( document.getElementById( 'foo' ) );
现在,原生函数就是原生函数,浏览器不允许我们访问它,当然,它甚至不是 JS 函数。
关于html - "document.getElementById()"函数存储在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61987959/