stack = !options.once && [];
if ( list ) {
if ( stack ) {
if ( stack.length ) {
fire( stack.shift() );
}
} else if ( memory ) {
list = [];
} else {
self.disable();
}
}
问题1: 当$.Callbacks('once')的时候,在fireWith中 if ( list && ( !fired || stack ) ) 已经做了处理,比如 第一次fire() fired = false 第二次fire() fired = true; stack = false;就可以实现触发一次效果,源码为什么要第一次fire()时,要触发self.disable() 让list = undefined呢 岂不是多此一举
问题2: 当$.Callbacks('memory')时,add( fn ) 此时因为if( memory )为true 所以可以再次调用fire()方法,此时通过修改firingIndex触发最后添加的那个函数,为什么当$.Callbacks('once memory')的时候,走了上面的else if判断 把list = []; 完全可以还是走if( memory )为true 再次调用fire()方法,list =[]岂不是多此一举