简单应用:利用高阶函数在不改变原有函数逻辑的情况下,插入函数
//highOrderFunction.js
const core = (argsA, argsB, argsC) => {
console.log(argsA, argsB, argsC)
}
Function.prototype.insertBefore = function (callFunc) {
return (...args) => {
callFunc()
this(...args)
}
}
const insertBeforeFunc = core.insertBefore(() => {
console.log('before call')
})
insertBeforeFunc('a', 'b', 'c')
// before call
// a b c