April 2, 2010

firefox setTimeout lateness argument

dijit.Dialog uses an animation when you hide it. because of this, if you want to destroy the dialog after hiding it, you have to use a setTimeout to let the animation finish before you destroy it.


setTimeout(dojo.hitch(dlg, 'destroyRecursive'), dijit.defaultDuration);


you would expect this to simply destroy the dialog and any content it contains. however, i was finding that sometimes, the domNode still remained after destroying the dialog.

after some quick debugging, i was seeing that destroyRecursive was being passed an integer as it's first parameter. destroyRecursive has an option to provide a preserveDom parameter and it will preserve the dom and so it was interpreting this integer as my intention to have the dom preserved. this was not my intention, so where was this integer coming from?

i headed straight to mozilla developer center and took a look at the docs for setTimeout. it turns out that firefox passes a lateness argument. you can see this happening with this snippet of code:


setTimeout(console.log, 100);


in my case, to make sure that the destroyRecursive function was doing what i intended it to do, i had to explicitly provide the first parameter via dojo.hitch


setTimeout(dojo.hitch(dlg, 'destroyRecursive', false), dijit.defaultDuration);

1 comment:

  1. Ah I see you got burned by the lateness "feature" too. Way to go Mozilla!

    ReplyDelete