SetTimeout problem in Firefox

The menu system should expand and collapse in accordance with the specified delay using the following operators ( o_item.getprop('hide_delay')returns 200 and o_item.getprop('expd_delay')returns 0):

this.o_showtimer = setTimeout('A_MENUS['+ this.n_id +'].expand(' + n_id + ');',
  o_item.getprop('expd_delay'));

and

this.o_hidetimer = setTimeout('A_MENUS['+ this.n_id +'].collapse();',
  o_item.getprop('hide_delay'));

I tried to put the code for the first argument in separate functions and call these functions as the first argument to setTimeout as follows:

this.o_showtimer = setTimeout( expandItem(this.n_id, n_id),
      o_item.getprop('expd_delay'));

Firebug issued the following error message:

useless setTimeout call (missing quotes around argument?)

And there were no delays in the collapse.

I put the argument in quotation marks (although recommended here ) as follows:

this.o_showtimer = setTimeout( "expandItem(this.n_id, n_id)",
  o_item.getprop('expd_delay'));

but it didn’t work. It turned out that nothing was happening at all and throwing some console.log () messages into the code confirmed this.

:

this.o_showtimer = setTimeout( function() { expandItem(this.n_id, n_id); },
  o_item.getprop('expd_delay'));

. IE (, , ), Firefox ( console.log() expandItem collapseItem , ).

:

this.o_hidetimer = setTimeout( function() { alert('test'); },
  o_item.getprop('hide_delay'));

! , - .

, setTimeout , this.o_showtimer, setTimeout fire. , - -.

:

var o_showtimer = setTimeout( function() { expandItem(this.n_id, n_id); },
  o_item.getprop('expd_delay'));

expandItem . , :

var o_showtimer = setTimeout( function() { expandItem(this.n_id, n_id); },
  o_item.getprop('expd_delay'));

 this.o_showtimer = o_showtimer;

setTimeout ! (expd_delay 0!).

+5
1

, Javascript 'this'. "expandItem" , , 'this' ().

var that = this;
this.o_showtimer = setTimeout( function() { expandItem(that.n_id, n_id); },
  o_item.getprop('expd_delay'));
+5

All Articles