Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Source code of implementation JavaScript internal methods

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?
like image 501
Fistright Avatar asked Apr 16 '16 00:04

Fistright


People also ask

What is source code in JavaScript?

Source code is the fundamental component of a computer program that is created by a programmer. It can be read and easily understood by a human being.

Where is JavaScript source code?

Go to the outer edge of a site (e.g. far left), then right-click and click on “View Page Source” (or the option that's similarly named). That will bring up all the HTML code, along with links to CSS files, Javascript, images, etc.

How many ways can you implement JavaScript?

There are 3 ways of writing a function in JavaScript: Function Declaration. Function Expression. Arrow Function.


1 Answers

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


like image 144
Matt C Avatar answered Oct 20 '22 22:10

Matt C