我正在尝试扩展Array.push方法,以便使用push将触发回调方法,然后执行正常的数组函数.
我不太清楚如何做到这一点,但这里有一些我一直在玩的代码都失败了.
arr = [];
arr.push = function(data){
//callback method goes here
this = Array.push(data);
return this.length;
}
arr.push('test');
Run Code Online (Sandbox Code Playgroud)