1. 程式人生 > >vue 數組更新大概原理(僅供理解)

vue 數組更新大概原理(僅供理解)

pre per res oid class nts bsp while -a

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 數組更新大概原理(僅供理解)