有点疑惑:Jquery
var callbacks = $.Callbacks("once");
callbacks.add(fn1);
callbacks.add(fn2);
callbacks.remove(fn1);
callbacks.fire("foo");
callbacks.fire("bar");
结果:
fn2 says:foo
var callbacks = $.Callbacks("once");
callbacks.add(fn1);
callbacks.add(fn2);
callbacks.remove(fn1);
callbacks.fire("foo");
callbacks.fire("bar");
结果:
fn2 says:foo
2015-09-10
if(args){
...
}else{
if(isArray){
for (; i < length; i++) {
value = callback.call(obj[i], i, obj[i]);
...
}
}else{
for(var i in obj){
value = callback.call(obj[i], i, obj[i]);
....
}
}
}
...
}else{
if(isArray){
for (; i < length; i++) {
value = callback.call(obj[i], i, obj[i]);
...
}
}else{
for(var i in obj){
value = callback.call(obj[i], i, obj[i]);
....
}
}
}
2015-09-07
首先需要注意一点:
callback中可传入的参数按顺序有:index, element。index是当前执行元素的索引,element则是当前元素本身。
因此callback = function(index, element){ do something... }
再者,本课的代码缺少了一部分,即当args不存在时的代码,代码如下:
callback中可传入的参数按顺序有:index, element。index是当前执行元素的索引,element则是当前元素本身。
因此callback = function(index, element){ do something... }
再者,本课的代码缺少了一部分,即当args不存在时的代码,代码如下:
2015-09-07