A detailed explanation of the examples
Filter Resolve
How does the code above work?
Click the button first to execute $. Deferred (), get defer with a lot of methods
Defer.resolve (5);
var donelist = jquery.callbacks ("Once Memory"), Faillist = Jquery.callbacks ("Once Memory"), Progresslist = Jquery.callba CKS ("Memory"), state = "Pending"; lists = {resolve:donelist,reject:faillist,notify:progresslist}for (key in lists) {D eferred[key] = lists[key].fire;deferred[key + "with"] = lists[key].firewith;} According to the above code can be//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;//so resolve (5) executed the
fire:function () {Self.firewith (this, arguments); Return this;},firewith:function (context, args) {//stack=[]; for true;firing false;flag={} if (stack) {if (fi Ring) {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]; that is self, and 5 memory =!flags.memory | | [Context, args]; Fired = true; firing = true; Firingindex = Firingstart | | 0; Firingstart = 0; Firinglength = List.length; for (; list && Firingindex < firinglength; firingindex++) {//The function is false after execution and Flags.stoponfalse is true when memory = TR ue;//Note that this executes the function if (list[firingindex].apply (context, args) = = = False && flags.stoponfalse) { Memory = true; Mark as halted break; }} firing = false; if (list) {if (!flags.once) {if (stack && stack.length) {mem Ory = Stack.shift (); Self.firewith (memory[0], memory[1]); }} else if (memory = = = True) {self.disable (); } else {//Finally, the list function group is assigned an empty value list = []; } } }
jquery1.7.2 's source code Analysis (c) $. Deferred