首页 > 代码库 > vue 数组更新大概原理(仅供理解)

vue 数组更新大概原理(仅供理解)

var a = [1,1,4]
var arrayProto = Array.prototype;
var arrayMethods = Object.create(arrayProto); 
Object.defineProperty(a, ‘push‘, {
    value: function(){
     var arguments$1 = arguments;

    // avoid leaking arguments:
    // http://jsperf.com/closure-with-arguments
    var i = arguments.length;
    var args = new Array(i);
    while (i--) {
      args[i] = arguments$1[i];
    }
    var original = arrayProto[‘push‘];
    var result = original.apply(this, args);

    console.log("触发响应,比如更新视图");
    return result;

   },
    enumerable: true,
    writable: true,
    configurable: true
  });

 

vue 数组更新大概原理(仅供理解)