I would like to have a list of functions of a JS code together with the sources for each function. I'm completely new in this area, I found that I need to build AST of the code and traverse it. By searching on the web I found this API, but it only gives me a list of function names, how can I extract the source code of functions?
You can make use of toString()
to convert the body of function into string. Try this
function someFunction(){
var crazyVariable = 10.123123123;
}
someFunction.toString();
it will return you this "function someFunction(){ var crazyVariable = 10.123123123; }"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.