Opened 13 years ago

Closed 13 years ago

#9457 closed defect (invalid)

setTimeout and dojo modules scope issues

Reported by: vincentastek Owned by: anonymous
Priority: high Milestone: tbd
Component: General Version: 1.3.1
Keywords: setTimeout scope Cc: [email protected]
Blocked By: Blocking:



I got a bug I can not expect under IE.

I got a dojo module js file which contains an object derived from a dijit.DropDownButton?. In my dojo object definition, I use a setTimeout to call a JS generic function defined in the same JS file but out of the object.

IE6 crashes with a "not valid object or function" error when the timeout is over and the function is called. FFX is ok.

If I call the function directly at the same spot, but without the setTimeout, it's OK.

If I put the JS generic function definition in a <script> tag in my jsp page, the setTimeout call works ok.

Any idea what's wrong with that ?

Attachments (1)

MouseOverDropDownButton.js (361 bytes) - added by vincentastek 13 years ago.
An example of JS file loaded in the module test.package

Download all attachments as: .zip

Change History (3)

Changed 13 years ago by vincentastek

Attachment: MouseOverDropDownButton.js added

An example of JS file loaded in the module test.package

comment:1 Changed 13 years ago by vincentastek

Concerning the example js file :

If the toto function is put in a <script> tag in the html file using this custom DropDownButton?, it will work. But as it is, it doesn't.

comment:2 Changed 13 years ago by dante

Resolution: invalid
Status: newclosed

yes, IE treats external scripts differently wrt to scope/global. Eugene provided a lengthy explanation in another ticket. if you intend the function to be globally accessible, you should stub it onto a namespace already provided/working, eg: test.toto = function(){}

also, it is generally a bad thing to use setTimeout("somefunction()", n) (ends up eval'ing). nicer to just pass the reference, assuming test.toto = function(){}: setTimeout(test.toto, n);

if you don't want the toto function exposed, wrap the whole thing in an anon function and create a closure, but still reference the function by variable:

var toto = function(){}; setTimeout(toto, n);

Note: See TracTickets for help on using tickets.