i am trying to get the body of a function in JavaScript but am unable to do so. Let's say I wanted to see the function body of the native toUpperCase() function of the String object:
document.write(String.prototype.toUpperCase.toString());
// returns function toUpperCase() { [native code] }
I tried this in Safari, Chrome, Firefox, all return the same thing. How do I access what that [native code] contents is?
* update *
The reason I stumbled onto this question, is because I was trying to do the following:
If I have two functions, one of which I want to invoke on the other, I want to access the first function's return value in the second, so that I can do function1().function2(). For example:
// create a global function that returns a value
function returnValue() {
x = "john";
return x;
}
// create a function that converts that value to uppercase
function makeUpperCase(){
return this.toUpperCase();
// "this" obviously doesn't work, but "this" is where I wanted to
// access the return value of a function I'm invoking makeUpperCase() on.
}
So I wanted to see how a function like toUpperCase() accesses the return value of a function it is invoked on.
returnValue().toUpperCase().