‘use strict‘ function getFuncName (){ var callerName; { let reg = /(\w+)@|at ([^(]+) \(/g; reg.exec(new Error().stack); //跑一次exec, 跑到第二个匹配 let regResult = reg.exec(new Error().stack); callerName = regResult[1] || regResult[2]; } console.log(callerName); }; function funcToKnow (){ getFuncName(); }; funcToKnow(); //funcToKnow
时间: 2024-10-29 15:35:52