获取函数原型的源代码
假设我做了以下几点:
String.prototype.myFunc = function(){ /* code here */ }
我刚刚创build了一个新的方法myFunc
,它可以用于每个string( "This is a test".myFunc()
)。
我的问题是:是否有可能,如果是,如何以编程方式获取myFunc
的源代码? (这是节点内)
您可以使用位于Function.prototype
的toString
方法作为string获取Function.prototype
。
var funcSource = String.prototype.myFunc.toString();