Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get native javascript functions source code?

Tags:

javascript

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

like image 273
jscripter Avatar asked Mar 13 '14 06:03

jscripter


People also ask

Where can I see JavaScript source code?

For most browsers, to view inline JavaScript in the HTML source code, do one of the following. Press the Ctrl + U keyboard shortcut. Right-click an empty area on the web page and select the View page source or similar option in the pop-up menu.

What is a native code in JavaScript?

Native code is computer programming (code) that is compiled to run with a particular processor (such as an Intel x86-class processor) and its set of instructions. If the same program is run on a computer with a different processor, software can be provided so that the computer emulates the original processor.

Are there built-in functions in JavaScript?

JavaScript has several "top-level" built-in functions. JavaScript also has four built-in objects: Array, Date, Math, and String. Each object has special-purpose properties and methods associated with it. JavaScript also has constructors for Boolean and Number types.

What is native code in Chrome?

Native Client is a set of open source tools that allow Chrome to run compiled C and C++ code the same way the browser currently runs JavaScript or other common web programming languages. Native Code offers both a security sandbox and a set of interfaces that provide C and C++ bindings to the capabilities of HTML5.


2 Answers

  1. Pick a browser
  2. Make sure it is an open source one
  3. Dig through its source code

Some repositories include:

  • Firefox
  • Webkit
  • Chromium

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.

Also note that the code that scrolls a page when the spacebar is pressed isn't even a function that is exposed to JS.

like image 60
Quentin Avatar answered Oct 01 '22 08:10

Quentin


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:

Standard ECMA-262

like image 44
Peter Avatar answered Oct 01 '22 09:10

Peter