js判断函数是否是箭头函数

597 阅读1分钟
const isArrowFunction = fn => {
    const str = fn.toString()
    // 判断函数体是否有花括号
    if (str.match(/{[\s\S]*}/)) {
        // 将花括号内的函数体去掉
        return str.replace(/{[\s\S]*}/, "").includes("=>")
    } else {
        return true
    }
}