js可以实现给一个数组监听吗?大师请进 $.when.apply(null, table).done(callback);这个是jquery里的吗?今天看到一个网上的例子,发现table=[]是个数组,用上$.when.apply就可以监听完成后执行callback 方法callback就是一个function();--------------------------------我问题是,怎么处理给一个数组监听,上面的例子数组操作完成执行callback,怎么实现的呢? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 把数组的方法再包一层push什么的执行完了再调一次回调函数 Array.prototype.add = function(item){ this.push(item); if(this.callback) this.callback.call(this,item);}然后你写数组,添加成员时不用push,使用addvar arr = new Array();arr.callback = function(item){alert(item);}arr.add('1');arr.add('2');arr.add('a'); 这里以push元素为例写个,需要的话自己举一反三。Array.prototype._push = Array.prototype.push;Array.prototype.push = function(v){ this._push(v); if(typeof this.pushListener == 'function') this.pushListener.call(this,v)}var a = [], b = [];a.pushListener = function(v){ alert('在数组a中添加新元素'+v);}a.push(1);b.pushListener = function(v){ alert('在数组b中添加新元素'+v);}b.push(1); 传递函数的问题 IE8和火狐 JS中文乱码问题 js显示数据绑定的图片 没有分数怎么办?谁能给我吗? 如何让frame等几秒后再加载? js乱码的问题! 急,在线等待~~~~~~~~~~~~~~~~~~~ js的超级难题。用js生成的表单内容,递交或怎么取到它的值? 只允许用户在客户端输入数字但是不能接收中文状态下的数字这怎么办如何才能接收中文状态下的数字 如何在文本框中分别验证“汉字”和“英文字符串”的长度,有高分哦!! ajax异步请求一个连接后,在连接处理返回之前,关掉浏览器或页面,后台会继续处理吗 如何用js重写asp?用for in语句
把数组的方法再包一层push什么的执行完了再调一次回调函数
this.push(item);
if(this.callback) this.callback.call(this,item);
}然后你写数组,添加成员时不用push,使用addvar arr = new Array();
arr.callback = function(item){alert(item);}arr.add('1');
arr.add('2');
arr.add('a');
Array.prototype.push = function(v){
this._push(v);
if(typeof this.pushListener == 'function') this.pushListener.call(this,v)
}
var a = [], b = [];
a.pushListener = function(v){
alert('在数组a中添加新元素'+v);
}
a.push(1);b.pushListener = function(v){
alert('在数组b中添加新元素'+v);
}
b.push(1);