Making a group of objects up and down

A

abozhilov

Again my dummy english. I will be try again. I want to excuse to all
of the member in this group. Sorry.

The difference in this case is.
First argument of setTimeout is reference.
You create anonymous function. When you create anonymous function,
will be return reference.
This reference isn't assigned to anything. After executed object who
referred this reference, that object will be marked to GC.
In this case first argument of setTimeout referred to `object` who
have [[Call]]
internal method. We don't need to parsing code. After
check for [[Call]] method will be execute function.
 
T

Thomas 'PointedEars' Lahn

abozhilov said:
This provide you, easy way to errors. Again my dummy words... I would
to say.

setTimeout('animate()', 200);
Looks like: eval('animate()');

This string 'animate()', will be parse and after that will be
executing.

You cannot know that for sure. For example, it is quite possible for an
optimization to take place in the form of creating a Function object once,
like with Function('animate()'), and calling that function when it is time.
This will be start to parsing after 200ms.

Not necessarily.
For my, this is very bad. If you have syntax error? How to catch
error in this case?

Error-handling can be built into the code to be executed.
This error not terminate current thread.

There are no threads.
But is error.

Yes, there are definitely disadvantages to passing a string literal here.
However:
Do you have a time for little explained, how it works setTimeout?
RTFM.

I thing setTimeout create new thread and execute code in that thread.
I will be very grateful to anybody if explain or share material for
setTimeout.

At least for Mozilla, RTSL.
I have and another question:
Why 'animate()' isn't parse when i call setTimeout?

'animate()' is parsed as a string literal. String literals are not
evaluated when passed, and it is defined that window.setTimeout/setInterval
execute code passed as a string argument only after the time in milliseconds
after the call.

A Function object is also _not_ evaluated when a reference to it is passed
to window.setTimeout/setInterval. Only lexical scoping binds identifiers
that are declared/defined in the outer execution contexts, and not in the
expression code, when used in the code of a function expression. That is an
intrinsic feature of the programming language, and only remotely related to
calling the host method of window.setTImeout/setInterval.
Here you are right, but if today i need from setTimeout, i never use
string value for first argument of setTimeout.

Passing a string value does have its advantages. Sometimes "lazy
resolution" of identifiers is wanted.


PointedEars
 
A

abozhilov

You cannot know that for sure.  For example, it is quite possible for an
optimization to take place in the form of creating a Function object once,
like with Function('animate()'), and calling that function when it is time.

That will be slow. I maked for self simply benchmark.

var TIMES = 10000,
func,
i = 0,
timer = new Date().getTime();
for (;i < TIMES; i++)
{
func = function(){};
}
timer = new Date().getTime() - timer;
document.write('1: ' + timer + '; body: ' + func.toString() + ';<br /

timer = new Date().getTime();
for (i = 0; i < TIMES; i++)
{
func = Function();
}
timer = new Date().getTime() - timer;
document.write('2: ' + timer + '; body: ' + func.toString() + ';<br /

I know, you write Function('animate()') only for example. But if
wrapped over new function in called function i will be
arguments.callee.caller;
Whatever, you give another point. But i keep thing, reference to
object who have [[Call]] is better from string literal.
Error-handling can be built into the code to be executed.
Why? How you catch syntax error in this string literal?
Look, i respect you. You have big erudition. I want just learn. I'm
not a man who want everything ready to use. I want just reading and
undurstand that been writing. And i want to talk about code. And my
question. Where TFM?

Thanks.
 
L

Lasse Reichstein Nielsen

Thomas 'PointedEars' Lahn said:
abozhilov wrote:

You cannot know that for sure. For example, it is quite possible for an
optimization to take place in the form of creating a Function object once,
like with Function('animate()'), and calling that function when it is time.

True, the semantics of setTimeout isn't as well described as the ECMAScript
language.

Interestingly, it is actually something that can be tested:

setInterval(/*Function*/("var re = /x/;" +
"if (re.foo == 1) { alert('SECOND CALL'); } " +
"re.foo = (re.foo || 0) + 1;"), 1000);

Every time this code is /parsed/, a RegExp object is created. If the
string is parsed anew for every interval trigger, then it will never
make an alert. If it is parsed once into a function and that function
is called several times, it will cause an alert the second time it's
called.

Removing the comment around "Function" and running again tests that
the implementation actually creates the RegExp during parsing, and
doesn't create a new RegExp object every time the /x/ is evaluated.

A quick check shows:
Opera: Parses once and creates a function.
Chrome and Firefox: Parses every time, and creates regexp when parsing.
IE8 and Safari 4: Doesn't create regexp when parsing, so this test
doesn't reveal anything.

IE8 and Safari aren't following the ECMAScript 3rd edition specification
here (but could be deliberatly following the 5th edition)

/L
 
T

Thomas 'PointedEars' Lahn

abozhilov said:
That will be slow.

Nonsense. Compiling the code into a Function object only once, and calling
that later several times, will undoubtedly be faster than both compiling and
calling it every time.
I maked for self simply benchmark. [...]

Your benchmark misses my point completely.
Error-handling can be built into the code to be executed.
Why? How you catch syntax error in this string literal?
try...catch...finally
[...] Where TFM?

I told you before, didn't I? That aside: RTFFAQ, STFW.


PointedEars
 
A

abozhilov

Nonsense.  Compiling the code into a Function object only once, and calling
that later several times, will undoubtedly be faster than both compiling and
calling it every time.

We talk about setTimeout. setTimeout execute callback once after
delay. When execute setTimeout in running execution context to
entering again in that execution context, you can't compile code only
once. And what is advantage to compile code when i can passed
reference to object who been initialized? In this case, i don't need
to compile anything.
try...catch...finally

How to prevent syntax error. I don't talk about runtime error. String
value for first argument of setTimeout, will be parse after delay. Why
setTimeout/setInterval isn't parse code, when i call they? If they
parse in them execution context, error handling will be see:

try {
setTimeout('JavaScript code', delay);
}catch(e)
{
console.log(e);
}
Do you have a time for little explained, how it works setTimeout?
RTFM.
[...] Where TFM?

I told you before, didn't I?  That aside: RTFFAQ, STFW.

I want to learn! When i search in google for any specification about
setTimeout/setInterval, i don't look any good results. Before i want
anything i ever try it first to help itself. I told you. I don't want
anything in ready aspect. Just i want hint and suggestion. That's all.
 
T

Thomas 'PointedEars' Lahn

abozhilov said:
We talk about setTimeout.

No, *you* are. It stands to reason that, because the general behavior of
window.setTimeout() and window.setInterval() is similar, the optimization
would apply to both methods.
setTimeout execute callback once after
delay. When execute setTimeout in running execution context to
entering again in that execution context, you can't compile code only
once.

Yes, you can.
And what is advantage to compile code when i can passed
reference to object who been initialized? In this case, i don't need
to compile anything.

I beg your pardon?
How to prevent syntax error. I don't talk about runtime error. String
value for first argument of setTimeout, will be parse after delay. Why
setTimeout/setInterval isn't parse code, when i call they? If they
parse in them execution context, error handling will be see:

try {
setTimeout('JavaScript code', delay);
}catch(e)
{
console.log(e);
}

window.setTimeout(
'try { JavaScript code } catch (e) { console.log(e) }', 420);

However, the try..catch would not be necessary in this case as the console
would report the syntax error anyway. And of course syntax errors can only
be *prevented* by using proper syntax.
Do you have a time for little explained, how it works setTimeout?
RTFM.
[...] Where TFM?
I told you before, didn't I? That aside: RTFFAQ, STFW.

I want to learn!

The read the FAQ, and search the Web. (Preferably you should learn English
or German, or Polish or ... first.) Virtually everything is there; the rest
is here (and in de.comp.lang.javascript, and probably
pl.comp.lang.javascript aso.)
When i search in google for any specification about
setTimeout/setInterval, i don't look any good results.

For me, the third hit in a Google Web search for "settimeout" or
"setinterval" points to MDC. And, unsurprisingly, the Google Groups search
for "settimeout" or "setinterval" here and in de.comp.lang.javascript yields
a number of good results.


PointedEars
 
A

abozhilov

Yes, you can.

setTimeout in my Firefox 3.0.13 isn't optimization like setInterval.
I beg your pardon?

Are you joking? You give me, very good thing. Thank's ;~)
And of course syntax errors can only
be *prevented* by using proper syntax.

Yes. That is right job. But string value for first argument of
setTimeout/Interval, provide easy way to make dummy typo error. This
error only visible when i run code. I don't want this.

The read the FAQ, and search the Web.  (Preferably you should learn English
or German, or Polish or ... first.)  Virtually everything is there; therest
is here (and in de.comp.lang.javascript, and probably
pl.comp.lang.javascript aso.)

Yes. Correct. I worked about this. I want one day, to write and speak
English better from now.
Sorry if at a moment i make dummy language error.
For me, the third hit in a Google Web search for "settimeout" or
"setinterval" points to MDC.  And, unsurprisingly, the Google Groups search
for "settimeout" or "setinterval" here and in de.comp.lang.javascript yields
a number of good results.

I see only "working draft" of HTML 5. Whatever, that enough about this
topic. Thanks for discussion.
 
S

SAM

Le 9/9/09 8:23 PM, Jorge a écrit :
There's no need to wrap animate in another function:

setTimeout(animate, 200);

It seems to me that one of my IE didn't want it.

At this time in what I think to be IE6 that works.
 
T

Thomas 'PointedEars' Lahn

abozhilov said:
setTimeout in my Firefox 3.0.13 isn't optimization like setInterval.

So you have read the source code?
Are you joking? You give me, very good thing. Thank's ;~)

For what? You should look up that common idiom in a dictionary.


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,222
Members
46,810
Latest member
Kassie0918

Latest Threads

Top