html - "document.getElementById()"函数存储在哪里?

标签 html dom

我想知道该函数存储在哪里?

我这么问是因为我尝试在 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/

相关文章:

javascript - 使用DOM方法normalize()的效果

javascript - 我可以使用 jQuery 访问影子 DOM 吗?

javascript - 使用 Nightwatch 访问 iFrame 元素

html - 如何根据条件添加样式

html - 按比例从 psd 实现页面

html - Div 没有停留在正确的位置

javascript - 在 onclick 中传递动态对象 - JavaScript/jQuery

javascript - 使用 jquery 和 javascript 水平滑动 div

javascript - 修改一个函数来传递图像

javascript - 绘制到第二个 Canvas 会取消第一个 Canvas