Ask Question Forum:
Model Library:2025-02-08 Updated:A.I. model is online for auto reply question page
C
O
M
P
U
T
E
R
2
8
Show
#
ASK
RECENT
←
- Underline
- Bold
- Italic
- Indent
- Step
- Bullet
- Quote
- Cut
- Copy
- Paste
- Table
- Spelling
- Find & Replace
- Undo
- Redo
- Link
- Attach
- Clear
- Code
Below area will not be traslated by Google,you can input code or other languages
Hint:If find spelling error, You need to correct it,1 by 1 or ignore it (code area won't be checked).
X-position of the mouse cursor
Y-position of the mouse cursor
Y-position of the mouse cursor
Testcursor
caretPos
Attachment:===
Asked by rwniceing
at 2024-08-22 07:05:46
Point:500 Replies:10 POST_ID:829190USER_ID:12079
Topic:
JavaScript;jQuery;Asynchronous Javascript and XML (AJAX)
For setTimeinterval() that can do callback function such as
window.setInterval(displaymesg,2000, "message is here");function displaymesg(mesg){document.getElementById("message-wrapper").innerHTML+= mesg;} 1:2:3:4:
The code above is working for all browsers except older version of IE browser.
The question is
1-it works for the browsers becoz they are using javascript closure to pass argument to the callback function, Right ?
2- it didn't work for IE old browser bcoz they did NOT use javascript closure to do that ,Right?
3- If item-1 is correct, they are using similar or concept closure javascript code as follows, Right ?
var displaymesg=closurefunc("message is here");"window.setInterval(displaymesg,2000);"function closurefunc(mesg){ function callbackfunc(){ document.getElementById("message-wrapper").innerHTML+=mesg;"}return callbackfunc;"} 1:2:3:4:5:6:7:8:
Or there is other method besides closure to pass the argument into callback function ?
Please advise
Rwniceing
Author: rwniceing replied at 2024-08-22 23:35:02
Thanks for all of reply
Answer to Question on the topic post
1-NO, there is no need to use closure to do the setInterval() for those browser works for setInterval since it is specified from http://www.w3schools.com/jsref/met_win_setinterval.asp and from from pre ECMA standards
2-Yes, for IE laterst version, setInterval is not working since IE is not support passing back the callback argument, we can use the closure to solve it as previous code attached OR use other technique such as IE-specific compatibility code found from https://developer.mozilla.org/en/docs/Web/API/window.setInterval
3- Correct and if IE laterst version is not working for setInterval, or read item-2 above
Answer to Question on the topic post
1-NO, there is no need to use closure to do the setInterval() for those browser works for setInterval since it is specified from http://www.w3schools.com/jsref/met_win_setinterval.asp and from from pre ECMA standards
2-Yes, for IE laterst version, setInterval is not working since IE is not support passing back the callback argument, we can use the closure to solve it as previous code attached OR use other technique such as IE-specific compatibility code found from https://developer.mozilla.org/en/docs/Web/API/window.setInterval
3- Correct and if IE laterst version is not working for setInterval, or read item-2 above
Assisted Solution
Expert: Rob Jurd replied at 2024-08-22 23:16:25
125 points EXCELLENT
Older versions you can, new versions do not. You can't pass the variable the way you were going.
What you've assumed above is correct
What you've assumed above is correct
Author: rwniceing replied at 2024-08-22 22:26:13
In other words,
Answer to Question on the topic post
1-NO, there is no need to use closure to do the setInterval() for those browser works for setInterval since it is specified from http://www.w3schools.com/jsref/met_win_setinterval.asp
2-Yes, for old browser such IE older version, setInterval is not working since IE is not support passing back the callback agrument, we can use the closure to solve it as previous code attached OR use other technique such as
IE-specific compatibility code found from https://developer.mozilla.org/en/docs/Web/API/window.setInterval
3- Correct, if IE is not working for old browser for setInterval, or read item-2 above
I think I concluded those my question with the the asnwer above that is okay, Right ?
Finally question is I heard some IE is not working setInterval with passing argument, Is it right for older version of IE or latest version of IE ? I 'm confusing that.
Answer to Question on the topic post
1-NO, there is no need to use closure to do the setInterval() for those browser works for setInterval since it is specified from http://www.w3schools.com/jsref/met_win_setinterval.asp
2-Yes, for old browser such IE older version, setInterval is not working since IE is not support passing back the callback agrument, we can use the closure to solve it as previous code attached OR use other technique such as
IE-specific compatibility code found from https://developer.mozilla.org/en/docs/Web/API/window.setInterval
3- Correct, if IE is not working for old browser for setInterval, or read item-2 above
I think I concluded those my question with the the asnwer above that is okay, Right ?
Finally question is I heard some IE is not working setInterval with passing argument, Is it right for older version of IE or latest version of IE ? I 'm confusing that.
Assisted Solution
Expert: Rob Jurd replied at 2024-08-22 19:04:17
125 points EXCELLENT
https://developer.mozilla.org/en/docs/Web/API/window.setInterval
Callback Arguments:
https://developer.mozilla.org/en/docs/Web/API/window.setInterval#Callback_arguments
Note that passing additional parameters to the function in the first syntax does not work in Internet Explorer 9 and below. If you want to enable this functionality on that browser you must use a compatibility code (see the Callback arguments paragraph).
Callback Arguments:
https://developer.mozilla.org/en/docs/Web/API/window.setInterval#Callback_arguments
Expert: Rob Jurd replied at 2024-08-22 18:58:37
Any questions let me know
Accepted Solution
Expert: Rob Jurd replied at 2024-08-22 18:58:18
125 points EXCELLENT
Not so much to do with closure but as Gary indicated about how the browsers interpreted the pre ECMA standard, so their implementation was different.
To reiterate Gary's code
To reiterate Gary's code
var msg = "message is here";window.setInterval(function() { displaymesg(msg);},2000);function displaymesg(mesg){ document.getElementById("message-wrapper").innerHTML+= mesg;}; 1:2:3:4:5:6:7:8:
#a40278995 There is no closure here. The setInterval function is defined as:
http://www.w3schools.com/jsref/met_win_setinterval.asp
Mozilla: https://developer.mozilla.org/en/docs/Web/API/window.setInterval, which talks about how closures are avoided
Author: rwniceing replied at 2024-08-22 07:48:39
Gary, your code seems different from window.setInterval(displaymesg,2000, "message is here");
If you code is corrrect, we don't need to use closure on setInterval since it can pass
"msg here" into displaymesg function argument directly from your code without any closure code help, Right ? If so, the item-1 question is not correct .
If you code is corrrect, we don't need to use closure on setInterval since it can pass
"msg here" into displaymesg function argument directly from your code without any closure code help, Right ? If so, the item-1 question is not correct .
Assisted Solution
Expert: Gary replied at 2024-08-22 07:45:23
125 points EXCELLENT
setInterval (and the similar setTimeout) are from pre ECMA standards, so browsers could interpret and implement them however they liked
These days all browsers operate (almost) to the ECMA standards
I don't have time to find the docs on it at the mo.
These days all browsers operate (almost) to the ECMA standards
I don't have time to find the docs on it at the mo.
Author: rwniceing replied at 2024-08-22 07:31:07
Gary, you mean
1-Yes,
2-Yes, old browser did not use closure
3-Yes, similar concept code as attachment above(just for concept only)
All "yes" ,Right ?
Last question before closing this thread , why older browser didn't use closure ? Is it becoz closure feature implemented in latest version of browser from suggestion from latest ECMA script specification ?
In other words, in the past there is no closure concept or thing in javascript
Please advise
1-Yes,
2-Yes, old browser did not use closure
3-Yes, similar concept code as attachment above(just for concept only)
All "yes" ,Right ?
Last question before closing this thread , why older browser didn't use closure ? Is it becoz closure feature implemented in latest version of browser from suggestion from latest ECMA script specification ?
In other words, in the past there is no closure concept or thing in javascript
Please advise
Expert: Gary replied at 2024-08-22 07:18:54
Correct