实现JavaScript内部方法的源代码 [英] Source code of implementation JavaScript internal methods

查看:48
本文介绍了实现JavaScript内部方法的源代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法查看JavaScript方法背后的代码?不是网站.html或.js文件中的javascript方法,而是JavaScript的内部方法.

例如:

  • 如何查看JavaScript如何计算元素的 offsetTop ?

解决方案

JavaScript由浏览器实现,因此取决于浏览器.

Google的浏览器 Chrome git存储库此处中查看其所有源代码.请在我的答案底部查看有关Chrome-Chromium关系的更多信息.

Mozilla的浏览器 Firefox 是开源的,就像其所有项目一样.您可以在此处查看Mozilla项目的所有源代码.您将在此处中找到实现Firefox的JavaScript的代码./p>

对于像Chrome那样的JavaScript的封闭源实现,您永远不能确切确切地了解每种方法的工作方式.通过阅读可用的文档(请参阅下文),您将能够 最佳 了解如何实现方法.

注意,仅因为 Chrome 的源代码基于开放源代码项目 Chromium ,但这并不意味着源代码是 相同 .Chrome可能已经对JavaScript方法进行了调整,但我们不知道.我认为这不太可能,而且Chrome和Chromium之间的所有差异都很有可能列出在此Wikipedia页面上,并有一个不错的帖子此处进一步了解Chromium的源代码.

Chrome JS文档


Is there a way to see the code behind a JavaScript's method? Not a javascript method from the website's .html or .js files, but JavaScript's internal methods.

For example:

  • How can I see how JavaScript calculates the offsetTop of an element?

解决方案

JavaScript is implemented by the browser, so it depends on the browser.

Google's browser, Chrome, is closed-source not open-source. Which means that you can't view their source code, including their implementation of JavaScript. But, Chrome's source code is based on Chromium's source code, which is open source. You can view all of its source code in its git repository here. See more about this Chrome-Chromium relationship at the bottom of my answer.

Mozilla's browser, Firefox, is open-source just like all of their projects. You can view all of the source code for Mozilla projects here. You'll find the code that implements JavaScript in Firefox right here.

For closed-source implementations of JavaScript, like Chrome's, you can never be sure exactly how each method works. By reading the documentation available (see below), you will be able to get the best available idea of how a method might be implemented.

Note that just because Chrome's source code is based off of the open source project, Chromium, that doesn't mean the source code is the same. Chrome could have made tweaks to to JavaScript methods, and we wouldn't know. I think that is unlikely though, and all of the differences between Chrome and Chromium are most likely listed on this wikipedia page, and a nice post is available here on AskUbuntu

You can learn a lot more about Chromium's source code here.

Chrome JS documentation


这篇关于实现JavaScript内部方法的源代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆