Opened 12 years ago
Closed 12 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: |
Description
Hi,
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)
Change History (3)
Changed 12 years ago by
Attachment: | MouseOverDropDownButton.js added |
---|
comment:1 Changed 12 years ago by
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 12 years ago by
Resolution: | → invalid |
---|---|
Status: | new → closed |
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);
An example of JS file loaded in the module test.package