So, I'm looking for toSourceString() method for Function object which will return the source code of the Function object in String format.
For example, If I have
(function(a, b) {
function useThis(c,d) {
return 'hello' + c + d;
}
console.log(useThis('Jenny', 'Jim'));
}).bind(this);
kind of function, then I wish if I run toSourceString(), I will just get the inner source part of the function like:
function useThis(c,d) {
return 'hello' + c + d;
}
console.log(useThis('Jenny', 'Jim'));
Is there any default function that works across browsers? Or is there any Regex way to find some string and replace/remove the first and the end?
toString- but on how to extract the original function afterbind. Would be great to have a clarification - isbindin the question intentional, or not.Function.prototype.bindactually creates a new function, that invokes the 'original' one with a set context (one can check_.bindsource, for example, to study the approach). The point is, the new function is basically a compiled one - that's why itstoSourceshows just[native code]or something similar.