[英]How to get native javascript functions source code?
In console it appears as native function but I'd like to know how they were constructed.在控制台中,它显示为本机功能,但我想知道它们是如何构造的。 For example what is the code which executes when pressing space bar to scroll the page.
例如,按下空格键滚动页面时执行的代码是什么。 That info would teach me a lot, and I could make my functions more effective
这些信息会教给我很多东西,我可以让我的功能更有效
Some repositories include:一些存储库包括:
Note that JavaScript native functions are generally not written in JavaScript (expect C or C++ most of the time).请注意,JavaScript 原生函数通常不是用 JavaScript 编写的(大多数情况下是 C 或 C++)。 They are just exposed to JS through an API.
它们只是通过 API 暴露给 JS。
Also note that the code that scrolls a page when the spacebar is pressed isn't even a function that is exposed to JS.另请注意,按下空格键时滚动页面的代码甚至不是向 JS 公开的函数。
While this will not show you actual source code, if you're interested in how many of the native JavaScript functions are implemented, you can peruse the specification upon which they are based:虽然这不会向您显示实际的源代码,但如果您对实现了多少本机JavaScript函数感兴趣,您可以仔细阅读它们所基于的规范:
What is V8?什么是V8?
The contract for exactly how the Javascript built-ins should behave is outlined in the ECMAScript specification (see example for Array.every()
). ECMAScript 规范中概述了 Javascript 内置函数的确切行为方式(参见
Array.every()
的示例)。
There are a number of different Javascript engines, each with their own specific implementation of ECMAScript.有许多不同的 Javascript 引擎,每个引擎都有自己特定的 ECMAScript 实现。 The most common Javascript engines are (links point to code for
Array.every()
):最常见的 Javascript 引擎是(链接指向
Array.every()
的代码):
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.