I have been Googling this, but I can't seem to find a way I can read the code behind standard JavaScript methods such as Object.prototype.toString()
or Document.getElementsByTagName()
. If no such method exists, is there any way to unwrap the internal complexity of a JavaScript object after it has been encapsulated?
For custom functions, you can actually call the toString() method to see the code. For example, on a page that has jQuery:
>> $.toString()
"function (a,b){return new e.fn.init(a,b,h)}"
But when you call:
>> toString.toString()
You get:
"function toString() {
[native code]
}"
The native code is not written in JS, I'm guessing it's C++. You can see the source in the corresponding JS interpreter project, e.g. V8.