I prototyped Function
so that it has a getBody function:
Function.prototype.getBody = function() {
// Get content between first { and last }
var m = this.toString().match(/\{([\s\S]*)\}/m)[1];
// Strip comments
return m.replace(/^\s*\/\/.*$/mg,'');
};
See here for more info. I tried to test it this way:
console.log(console.log.getBody.getBody());
but received an error: TypeError: console.log.getBody is undefined
.
I figured out that maybe this happens because console.log
was defined before I actually prototyped Function
so I created an empty function x
right before the prototyping and tried to call
console.log(x.getBody.getBody());
which worked without a problem. Checking the type of console.log
with typeof console.log
results in "function". Here's a CodePen to try it out. All of this wasn't really a surprise since it's what I expected except of console.log.getBody
to be undefined.
So why does prototyping Function
not affect console.log
? I'm using Firefox 18.0.1 with Firebug 1.11.1.