Discussion on variable scopes in javascript callback functions _ javascript skills

Source: Internet
Author: User
For more information about variable scopes in callback functions, see. 1. Background
The callback function in Javascript is familiar to everyone. The most obvious example is the callback function provided during Ajax requests,
In fact, the event processing method (onclick, ondblclick, etc.) of DOM nodes is also a callback function.
When using DWR, the callback function can appear as the first or last parameter, for example:
JScript code function callBack (result) {} myDwrService. doSomething (param1, param2, callBack); // DWR recommended method // or myDwrService. doSomething (callBack, param1, param2 );

2. Problem Description
Recently, when I was using Dojo + Dwr, I encountered a problem:
If the callback function belongs to an object (marked as obj1), when DWR executes the callback function,
The context is not obj1.
The symptom is that any attribute accessing obj1 In the callback function is undefined.
Versions: Dojo1.3.1 and dwr2
3. Simulate the problem code
The following test code can simulate this problem:
JScript code

The Code is as follows:




Related Article

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.