[英]How do I get the “children” or contents of a function?
For example, if my script is... 例如,如果我的脚本是...
function cool() {
function yes() { alert('yes'); }
function wow() { alert('wow'); }
}
And I use cool.toString();
我使用
cool.toString();
then I get the entire function as a string. 然后我将整个函数作为字符串获取。
But what do I have to do to just get the inner-contents as a string: 但是我要怎么做才能使内部内容成为字符串:
function yes() { alert('yes'); }
function wow() { alert('wow'); }
toString
to get the entire function, like just did in your example toString
来获取整个函数,就像您在示例中所做的一样 {
with an empty string. {
为止。 Like this: 像这样:
cool.toString().replace(/^[^{]*{/, "").slice(0, -1)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.