jquery1.7.2 source Analysis (c) $. Deferred

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.