例子的详细讲解
Filter Resolve
上面的的代码是怎么运行的呢
点击button的先执行 $.Deferred(),得到具有很多方法的defer
defer.resolve( 5 );
var doneList = jQuery.Callbacks( "once memory" ), failList = jQuery.Callbacks( "once memory" ), progressList = jQuery.Callbacks( "memory" ), state = "pending"; lists = { resolve: doneList, reject: failList, notify: progressList } for ( key in lists ) { deferred[ key ] = lists[ key ].fire; deferred[ key + "With" ] = lists[ key ].fireWith; } //根据上面的代码可得 //deferred[ ‘resolve‘]=lists[ ‘resolve‘].fire; //deferred[ ‘resolveWidth‘]=lists[ ‘resolve‘].fireWith; //deferred[ ‘reject‘]=lists[ ‘reject‘].fire; //deferred[ ‘rejectWidth‘]=lists[ ‘reject‘].fireWith; //deferred[ ‘notify‘]=lists[ ‘notify‘].fire; //deferred[ ‘notifyWidth‘]=lists[ ‘notify‘].fireWith; //因此resolve( 5 )执行了
fire: function() { self.fireWith( this, arguments ); return this; }, fireWith: function( context, args ) { //stack=[];为true;firing 为false;flag={} if ( stack ) { if ( firing ) { if ( !flags.once ) { stack.push( [ context, args ] ); } //memory =undefined } else if ( !( flags.once && memory ) ) { fire( context, args ); } } return this; }
fire = function( context, args ) {
args = args || [];
//memory = [ context, args ];即为self,和5
memory = !flags.memory || [ context, args ];
fired = true;
firing = true;
firingIndex = firingStart || 0;
firingStart = 0;
firingLength = list.length;
for ( ; list && firingIndex
jquery1.7.2的源码分析(三)$.Deferred时间: 2024-10-13 20:13:08