This is a discussion on ".call or .apply with setTimeout" within the JavaScript Forum section. This forum, and the thread ".call or .apply with setTimeout are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
.call or .apply with setTimeout
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
|||
|
.call or .apply with setTimeout
How do I get the below timeout to work? After reading http://www.west-wind.com/WebLog/posts/5033.aspx I think I need to use .call or .apply within the timeout, but I can't figure out how to use them?
|
|
|
|
||||
|
Re: .call or .apply with setTimeout
The first argument of setTimeout is an evaluated string so you just need to place quotes around it.
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
|
|
|||
|
Re: .call or .apply with setTimeout
Thanks for the pointer, but I still can't get it to work using that code. Also, I tried removing the reference to this.bye() from seti(), and still got the error from the timeout "this.bye is not a function", so I think its trying to create a new hello object but with 'this' pointing to the window object.
|
|
||||
|
Re: .call or .apply with setTimeout
That's right, you can't use the this keyword because it is not available in the scope from where you're calling it.
You can look at naming the obj so it can be aware within the function:
var jim = new hello('jim');
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
|
|
|||
|
Re: .call or .apply with setTimeout
Thank you so much for that, works great!
Edit: Mark thread as solved isn't appearing in the Thread Tools for me, so if a Mod can mark this thread as solved, it would be appreciated. Last edited by djeyewater; Feb 10th, 2008 at 13:38. |
|
|||
|
Re: .call or .apply with setTimeout
You can also accomplish this with a "closure" variable pointing to "this"
var self = this; setTimeout(function() {self.seti(); }, 1000); This way is much less limiting then working with strings. If you need to pass parameters to your function, look into the "hitch" method which uses call and apply and allows for arguments. |
![]() |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Problem with setTimeout in method | Emancip8 | JavaScript Forum | 1 | Apr 22nd, 2008 16:30 |
| Apply transition to a div | blkskull | JavaScript Forum | 0 | Feb 26th, 2008 14:00 |
| setTimeout won't work | cheataweb | JavaScript Forum | 1 | Dec 27th, 2006 00:26 |
| Beginning to Apply my skillz... | courtjester | Classic ASP | 7 | Apr 5th, 2004 10:18 |