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: