简单应用:利用高阶函数在不改变原有函数逻辑的情况下,插入函数

    1. //highOrderFunction.js
    2. const core = (argsA, argsB, argsC) => {
    3. console.log(argsA, argsB, argsC)
    4. }
    5. Function.prototype.insertBefore = function (callFunc) {
    6. return (...args) => {
    7. callFunc()
    8. this(...args)
    9. }
    10. }
    11. const insertBeforeFunc = core.insertBefore(() => {
    12. console.log('before call')
    13. })
    14. insertBeforeFunc('a', 'b', 'c')
    15. // before call
    16. // a b c