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 });
时间: 2024-10-17 02:00:55