473,785 Members | 3,157 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

setTimeout different behaviour in Firefox and IE

Hi all.
I didn't find anything on the web regarding this different behaviour I
found in Firefox (v. 2) and IE (v. 6), so I'm posting it here, maybe
someone will benefit from this.

I have a function in a javascript object like this:

function MyObject.protot ype = {
myvar = "This is myvar";
myfunction(myar g) {
// do something with myarg
}

}

If I issue a setTimeout call using a function with some additional
arguments in this form:

setTimeout(this .myfunction, 5, this.myvar);

(for example in another MyObject method), Firefox calls myfunction
passing myvar correctly (as a string valued "This is myvar"). Internet
Explorer seems to pass myvar as undefined.

My idea is that FF evaluates immediately the value to pass to the
function, stores it, and then when the time comes, invokes the
function with the correct value.
Instead it seems (but this is my guess) that IE evaluates the argument
only when it calls the function, thus having lost in the scope the
reference to "this".

I don't have tried it but I think that if I pass global variables or
"local" variables to the setTimeout additional arguments, they work...

Well... I just found this two different doc for setTimeout. I have a
JS reference in PDF (a bit old, referring to 1.3 version) that
complies with the second. This may be the reason why I get
undefined...
http://msdn2.microsoft.com/en-us/library/ms536753.aspx
http://developer.mozilla.org/en/docs...imeout#1021427

Just for the sake of completeness: I was using MochiKit so i resolved
using a partial(), when invoking setTimeout thus binding at setTimeout
invoke time the argument values. Worked fine.

Aug 21 '07 #1
1 14047
On Aug 21, 7:49 pm, "alex.malgar... @gmail.com"
<alex.malgar... @gmail.comwrote :
Hi all.
I didn't find anything on the web regarding this different behaviour I
found in Firefox (v. 2) and IE (v. 6), so I'm posting it here, maybe
someone will benefit from this.

I have a function in a javascript object like this:

function MyObject.protot ype = {
That is a plain syntax error. The rest of your code is similarly
plagued with errors. If you post code, it should be able to be copied
and pasted into a page and exhibit the behaviour you describe.

myvar = "This is myvar";
If that line is ever is ever executed (in your example, it isn't) it
will create a global property myvar with a value of "This is myvar".
myfunction(myar g) {
// do something with myarg
}
More syntax errors...
}

If I issue a setTimeout call using a function with some additional
arguments in this form:

setTimeout(this .myfunction, 5, this.myvar);
I guess this is your actual question. The answer is here:

<URL: http://developer.mozilla.org/en/docs...dow.setTimeout >

Gecko-based browsers (such as Firefox) accept additional parameters to
setTimeout, IE (and probably most other browsers) don't.
--
Rob
Aug 21 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
10652
by: Lian | last post by:
Hi all, It is a newbie's question about html tag "img". The attributes "title" and "alt" for "img" seems having the same function. So what is the main difference between them? Can i use them at the same time and set different values? Thank you for suggestions!
3
8595
by: jshanman | last post by:
I've created a "Play" button for my timeline that uses the Google Maps API. It basicly scrolls the timeline x interval every y milliseconds. The problem is the browser responds slowly even after the "Stop" button is clicked. (it responds slowly while playing, but thats to be expected with everything that it is doing) How can I get the browser back to it's more responsive state after the timeout is cleared? Here is the function that...
12
5556
by: Andrew Poulos | last post by:
With the following code I can't understand why this.num keeps incrementing each time I create a new instance of Foo. For each instance I'm expecting this.num to alert as 1 but keeps incrementing. Foo = function(type) { this.num = 0; this.type = type this.trigger(); } Foo.prototype.trigger = function() {
28
5310
by: Andre | last post by:
Hi, Does anyone know whether the ECMA, or an other standard document, specifies a maximum for the value that can be pass to the setTimeOut() function in Javascript? Andre
3
2085
by: masonsimon | last post by:
I'm trying to use the following function to update an Opera widget that I'm writing, but it doesn't seem to work. function runAt(time_to_run_at, what_to_run) { //time_to_run_at is a Date //what_to_run is either a function reference or a string of JavaScript var now = new Date();
2
2043
by: Noggon | last post by:
My function, called first() keeps coming back to me in the javascript console as being undefined. Yet I can't think why it isn't loaded. Maybe I'm brain dead, so could use some help! :-) What I'm trying to do is to have functions call each other at intervals of 2 seconds, each changin a src of an image as they do so.
2
1380
by: back_ache | last post by:
Hi, I have created a script that needs to constanstly poll a webpage, I do this with a controling function that fires off different functions to do the work, then restarts by calling itself after a second using settimeout. on IE it runs forever, on firefox it stops after a while, what am I doing wrong?
9
6726
by: pengypenguin | last post by:
As we know, Javascript suffers an insufferable lack of a wait() or sleep() function, and so setTimeOut must step in to take up the slack. A function can use setTimeOut like sleep() by calling itself after x seconds. This begs a few questions: Is this design building enormous calling stacks to nowhere? Will the users machine eventually run out of memory space to contain this stack? How can this be avoided? Thanks, -- Whit Nelson
1
9537
by: bizt | last post by:
Hi, I have a process where every so often I refresh a table's data using a setTimeout() .. and when its no longer needed, a clearTimeout(). The following is a simple example of how this is done: var goMenuTimeout = null; function LoadMenu() { // cancel any repeat actions
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10148
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9950
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8972
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7499
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3646
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.