javascript 如何获取原生javascript函数源代码?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22371251/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get native javascript functions source code?
提问by jscripter
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
在控制台中,它显示为本机函数,但我想知道它们是如何构造的。例如按空格键滚动页面时执行的代码是什么。这些信息会教会我很多东西,我可以让我的功能更有效
采纳答案by Peter
While this will not show you actual source code, if you're interested in how many of the native JavaScriptfunctions are implemented, you can peruse the specification upon which they are based:
虽然这不会向您展示实际的源代码,但如果您对实现了多少原生JavaScript函数感兴趣,您可以仔细阅读它们所基于的规范:
回答by Quentin
- Pick a browser
- Make sure it is an open source one
- Dig through its source code
- 选择浏览器
- 确保它是一个开源的
- 挖掘它的源代码
Some repositories include:
一些存储库包括:
Note that JavaScript native functions are generally not written in JavaScript (expect C or C++ most of the time). They are just exposed to JS through an API.
请注意,JavaScript 本机函数通常不是用 JavaScript 编写的(大多数情况下使用 C 或 C++)。它们只是通过 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 的函数。
回答by Jeach
What is V8?
V8是什么?
- V8 is Google's open source JavaScript engine.
- V8 implements ECMAScript as specified in ECMA-262.
- V8 is written in C++ and is used in Google Chrome, the open source browser from Google.
- V8 can run standalone, or can be embedded into any C++ application.
- V8 project page: https://github.com/v8/v8/wiki
- V8 source code: https://github.com/v8/v8
- V8 是 Google 的开源 JavaScript 引擎。
- V8 实现了 ECMA-262 中指定的 ECMAScript。
- V8 是用 C++ 编写的,用于谷歌的开源浏览器 Google Chrome。
- V8 可以独立运行,也可以嵌入到任何 C++ 应用程序中。
- V8 项目页面:https: //github.com/v8/v8/wiki
- V8 源代码:https: //github.com/v8/v8