From this, I found out that JavaScript is written in C++. I also have found out/deduced that a majority of JavaScript is C++ (e.g. Math.atan+""
and Math.atan.toString()
yielding "function atan() { [native code] }"
). The [native code
I assume to be C++, else what would be the point of 'hiding' it?
My question is there a way to utilize C++ in JavaScript? To use it in a function or in the JavaScript platform?
The emscripten project allows you to to generate Javascript from C and C++:
and through methods like ccall and cwrap you can call C functions:
Using the example from the site, this C++ code which used
extern "C"
to prevent name mangling:can be compiled like so:
and used in Javascript:
embind can be used for C++ functions and classes. The quick example from the site is as follows:
and compile:
and use in Javascript: