Reputation: 15099
Let's say I do the following:
String.prototype.myFunc = function(){ /* code here */ }
I have just created a new method, myFunc
, that will be available for each string ("This is a test".myFunc()
).
My question is: Is it possible, and if it is, how, to get the source code of myFunc
programatically? (This is inside Node)
Upvotes: 1
Views: 557
Reputation: 54011
You can obtain the function as a string using the toString
method that sits on Function.prototype
.
var funcSource = String.prototype.myFunc.toString();
Upvotes: 3