I want to do the opposite of Get JavaScript function-object from its name as a string?
That is, given:
function foo()
{}
function bar(callback)
{
for me, with just a little modification (adding \ before parent), this work:
if (Function.prototype.name === undefined){
// Add a custom property to all function values
// that actually invokes a method to get the value
Object.defineProperty(Function.prototype,'name',{
get:function(){
return /function ([^\(]*)/.exec( this+"" )[1];
}
});
}