gistfile1.txt let wow = function haha() { return 1 }; function getFunctionName(fn) { if(fn.name !== undefined){ return console.log(fn.name); } let ret = fn.toString(); ret = ret.substr('function '.length);//第二个参数未填默认到最后
let wow = function haha() { return 1 }; function getFunctionName(fn) { if(fn.name !== undefined){ return console.log(fn.name); } let ret = fn.toString(); ret = ret.substr('function '.length);//第二个参数未填默认到最后 ret = ret.substr(0,ret.indexOf('(')); return console.log(ret); } getFunctionName(wow);