函数的拦截操作

1.使用一个临时的函数名存储函数

2.重新定义原来的函数

3.定义扩展的功能

4.调用临时的那个函数

  function func() {
      console.log("原始的功能")
    }
    let _tmpFn = func;
    func = function () {
      _tmpFn();
      console.log("扩展的功能")
    }
    func()
    // 原始的功能
    // 扩展的功能

 vue重写push

let ARRAY_METHOD = [
      'push',
      'pop'
    ]
    let arryType_methods = Object.create(Array.prototype);
    ARRAY_METHOD.forEach(method => {
      // 调用原来的方法
      console.log('调用的是拦截的方法')
      let res = arryType_methods.prototype[method].apply(this, arguments)
      return res;
    })
    let arr = [];
    arr._proto_ = arryType_methods;
原文地址:https://www.cnblogs.com/chenzxl/p/14459968.html