Memo: recursive callee. Caller leads to an endless loop

Source: Internet
Author: User

Today, the Baobao Steamed Stuffed Bun shows that QW. eventh. getevent in qwrap may generate an endless loop.
CodeAs follows:

         /*  ** Obtain the event object * @ method getevent * @ Param {event} event (optional) the event object is the event * @ Param {element} element (optional) of the host where the call location is located by default) event * @ return {event} event object of the host Where any element object is located  */  Getevent:  Function  (Event, element ){  If  (Event ){  Return Event ;}  Else   If  (Element ){  If (Element.doc ument ){ Return  Element.doc ument. parentwindow. event ;}  If (Element. parentwindow ){ Return  Element. parentwindow. event ;}}  If  (Window. Event ){  Return Window. event ;}  Else  {  VaR F = Arguments. callee;  Do  {  If (/Event/. Test (F. Arguments [0]) { Return F. Arguments [0 ] ;}}  While (F = F. Caller );}}, 

 

This endless loop problem was also discussed in an example in:

VaR Getevent_count = 0 ;  Function  Getevent (e) {e = E | Window. event;  If (! E ){  VaR C = Arguments. callee. Caller;  While  (C ){  If (Getevent_count ++> 1000) ) {Alert ( 'Endless loops! ');  Return  ;} E = C. Arguments [0 ];  If (E && Typeof (E. altkey) = "Boolean "){ //  Duck typing                  Break  ;} C = C. Caller; e = Null  ;}} Return  E ;}  Function  Test (n ){  Return N? Test (n-1 ): Getevent ();} test ( 2 );

Causes of endless loops:Sometimes there is a closed loop in the caller chain.For example, the caller of a function may be equal to itself.

 

In addition, the QW. eventh. getevent method is not directly available to the Business Code personnel. Currently, no one has stepped on the issue and there is no need to change the implementation method.

 

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.