Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does " [native code] " mean?

I tried to investigate the jQuery code, so I used this:

document.write($.constructor); 

jsfiddle

I got this result:

function Function() { [native code] } 

What does [native code] mean? Why can't I see the real code?

Tested with Google-Chrome

like image 572
gdoron is supporting Monica Avatar asked Jun 27 '12 20:06

gdoron is supporting Monica


People also ask

What native code means?

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.

Why native code is needed?

Native code compilers eliminate the need for JVM and interpreters to convert the Java byte code, which is a portable intermediate code. By helping convert Java code directly into machine code, native code compilers help in reducing redundancy, reverse engineering and optimizing program execution.

What is native code in Android?

The Native Development Kit (NDK) is a set of tools that allows you to use C and C++ code with Android, and provides platform libraries you can use to manage native activities and access physical device components, such as sensors and touch input.

What are native code programming languages?

Sometimes referred to as the host language, the native language is the language understood by the computer. For example, binary is the language understood by the computer. In programming, native code is code that is written to run on a specific processor.


2 Answers

When you define functions in an interpreted language (as opposed to a compiled language). You have access to the file / string / text that defines the function.

In JavaScript for example you can read the definition body text of a function you have defined.

If you try to do the same for a function that is included by construction in JavaScript it is not implemented as text but as binary. There is no reason to show the binary code that implements that function because it is not readable and it might not even be available.

jQuery extends default JavaScript behaviour. It's one of the reasons it was so highly appreciated and praised as opposed to Prototype.js for example. Prototype was altering the natural behaviour of JavaScript creating possible inconsistencies when using Prototype alongside some other piece of code that relied on normal functionality.

tl;dr:

jQuery extends JavaScript, there is functionality implemented using native code (which performance wise is a good thing).

like image 104
Mihai Stancu Avatar answered Oct 07 '22 14:10

Mihai Stancu


$, jQuery is just a function. Without invoking it, it's just an ordinary function. A function's constructor is Function, hence $.constructor shows [native code].

like image 33
Rob W Avatar answered Oct 07 '22 14:10

Rob W