Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

SetTimeout question...

2 views
Skip to first unread message

Thomas Allen

unread,
Mar 30, 2009, 12:13:30 PM3/30/09
to
I'm trying to use SetTimeout to rotate some image sources, and I can't
get it to work. I know that there are other ways to pull this off, but
I'm curious as to what I need to change to get this script to work:

(function($) {
$(document).ready(function() {
var sponsors = $('.sponsors');
var sponsor_images = sponsors.find('img').remove();
var sponsor_frame = $('<img>').attr('src',
setTimeout(function() {
for(var i = 0; i < sponsor_images.length; i++) {
return $(sponsor_images[i]).attr('src');
};
}, 3000)
);
sponsors.html(sponsor_frame);
});
}) (jQuery);

If it isn't clear, here's what should happen:

1. Find the sponsor block
2. Extract the images as a jQuery object, removing them
3. Create a new image node
4. Set this image's source to change every three seconds to the next
one from the extracted images object

I've verified that the only part of the script that isn't working
properly is the setTimeout call, so I must be doing something wrong.

In case it's at all useful, here's the accompanying markup:

<div class="sponsors">
<img src="/handa/images/sponsors/aecom.png" alt="AECOM" />
<img src="/handa/images/sponsors/cdm.png" alt="CDM" />
<img src="/handa/images/sponsors/pankow.png" alt="Charles Pankow
Foundation" />
<img src="/handa/images/sponsors/moretrench.png" alt="Moretrench" />
<img src="/handa/images/sponsors/figg.png" alt="Figg" />
<img src="/handa/images/sponsors/hntb.png" alt="HNTB" />
<img src="/handa/images/sponsors/kiewit.png" alt="Kiewit" />
<img src="/handa/images/sponsors/mcgraw.png" alt="McGraw Hill
Construction - ENR" />
<img src="/handa/images/sponsors/weidlinger.png" alt="Weidlinger
Associates Inc. - Consulting Engineers" />
</div>

And I greatly appreciate any help!

Thanks,
Thomass

Thomas Allen

unread,
Mar 30, 2009, 12:20:48 PM3/30/09
to

Ah, this script's malfunction may be related to the fact that it's a
logical trainwreck. One second while I rewrite this...

Thomas

Thomas Allen

unread,
Mar 30, 2009, 12:26:04 PM3/30/09
to
On Mar 30, 12:13 pm, Thomas Allen <thomasmal...@gmail.com> wrote:

Here's a simpler alternative:

(function($) {
$(document).ready(function() {
var sponsors = $('.sponsors');
var sponsor_images = sponsors.find('img').remove();

var sponsor_frame = $('<img>');

for(var i = 0; i < sponsor_images.length; i++) {

setTimeout("sponsor_frame.attr('src', $(sponsor_images[i]).attr
('src'))", 3000);
};
sponsors.html(sponsor_frame);
});
}) (jQuery);

However, I don't understand scope inside of setTimeout: I get
"undefined" errors for all of the variables in the setTimeout command,
and I'm not too keen on making each one global.

Thomas

Erwin Moller

unread,
Mar 30, 2009, 12:51:44 PM3/30/09
to
Thomas Allen schreef:

If you can rewrite your script in such a way you don't use $ and JQuery,
maybe it becomes clearer and debugable (for me).
If you MUST use JQuery, why don't you post to their forum?

Regards,
Erwin Moller

--
"There are two ways of constructing a software design: One way is to
make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."
-- C.A.R. Hoare

Thomas Allen

unread,
Mar 30, 2009, 1:03:15 PM3/30/09
to
On Mar 30, 12:51 pm, Erwin Moller

Hi Erwin,

I know, but I felt that this was a more JavaScript-oriented question.
Here's a vastly simplified version of this script:

(function($) {
$(document).ready(function() {
var sponsors = $('.sponsors');

sponsors.images = sponsors.find('img').remove();
sponsors.frame = $('<img>');
sponsors.html(sponsors.frame);

for(var i = 0; i < sponsors.images.length; i++) {
sponsors.frame.attr('src', $(sponsors.images[i]).attr
('src'));
};
});
}) (jQuery);

In this script, everything is working properly, except I need
something like a sleep() function inside of the for loop, or an
equivalent. What would you recommend?

Feel free to hotlink our jQuery for testing (the jQuery-sensitive
parts work fine though).
<script src="http://www.asce.org/lib/javascript/jquery-1.2.6.js"
type="text/javascript"></script>

Thanks,
Thomas

Stevo

unread,
Mar 30, 2009, 1:16:20 PM3/30/09
to
Thomas Allen wrote:
> On Mar 30, 12:13 pm, Thomas Allen <thomasmal...@gmail.com> wrote:
>> I'm trying to use SetTimeout to rotate some image sources, and I can't
>> get it to work. I know that there are other ways to pull this off, but
>> I'm curious as to what I need to change to get this script to work:
>>
>
> for(var i = 0; i < sponsor_images.length; i++) {
> setTimeout("sponsor_frame.attr('src', $(sponsor_images[i]).attr
> ('src'))", 3000);


You'd probably need to create a closure for that
$(sponsors_images[i]).attr to find the correct image. You're passing
along a string to setTimeout that's going to be eval'ed after 3 seconds
but neither sponsor_images or i will exist at that time.

David Mark

unread,
Mar 30, 2009, 1:49:44 PM3/30/09
to

Really?

>
> (function($) {
>         $(document).ready(function() {
>                 var sponsors = $('.sponsors');

Bad design to start with. Shouldn't need to query elements by class
name.

>                 var sponsor_images = sponsors.find('img').remove();
>                 var sponsor_frame = $('<img>');

Is document.createElement too many characters?

>
>                 for(var i = 0; i < sponsor_images.length; i++) {
>                         setTimeout("sponsor_frame.attr('src', $(sponsor_images[i]).attr
> ('src'))", 3000);

Presumably something like this would have been less concise?

sponsor_frame.src = sponsor_images[i].src;

Do you understand what the "attr" method does? Per the wonderful
jQuery documentation, it gets/sets properties or attributes (hardly
interchangeable terms), depending on which paragraph you read. The
underlying code is just as confused. Obviously you are too or you
wouldn't be using it.

Here are some similar examples:

sponsor_frame.attr('onclick', 'alert("test")');
sponsor_frame.attr('onclick', function() { alert('test'); });
sponsor_frame.attr('rowspan', 6);
sponsor_frame.attr('rowSpan', 6);
sponsor_frame.attr('longdesc');
sponsor_frame.attr('longDesc');

Less concise, less efficient, slower, requires 50K of junk code and
there's not a person on earth that could tell you at a glance what
those do. The explanation would be the size of a dissertation anyway
and subject to change in the next jQuery version. :(

Contrast those to:

sponsor_frame.onclick = function() { alert('test'); };
sponsor_frame.rowSpan = 6;
sponsor_frame.longDesc;

One line each. No dependencies to upgrade. Works in *all* browsers
with *no* browser sniffing, misconceptions or glaring omissions to get
in the way. :)

Is it the "chaining" that fascinates? That pattern is not unique to
jQuery and isn't advisable anyway (further complicates debugging,
which isn't a strong suit for jQuery developers to begin with.)

>                 };
>                 sponsors.html(sponsor_frame);

So now you have an inefficient tangled up mess that will make hundreds
of function calls, executing all sorts of complicated code that
neither you nor John Resig understands.

http://groups.google.com/group/comp.lang.javascript/msg/96c5638a7f955e8f

If you had learned JavaScript rather than jQuery, you could write
legible and efficient code that is consistent across browsers and
won't break the next time jQuery is upgraded. The line above is sure
to work in every browser ever made and is completely transparent to
future developers. On the other hand, if anything goes wrong with
your chained attr calls, you have no recourse but to file a ticket and
pray. Read the other thread to get an idea of how effective that will
be.

>         });
>
> }) (jQuery);
>
> However, I don't understand scope inside of setTimeout: I get
> "undefined" errors for all of the variables in the setTimeout command,
> and I'm not too keen on making each one global.

This is what I'm talking about. You don't know Javascript and you are
leaning on similarly challenged individuals. Can any good come from
that at all? Maybe you save a few keystrokes on your way to producing
a monumental disaster of an application? What will you do when it
breaks? See the other thread about upgrades.

These are disruptive "technologies" alright. They are going to
disrupt HTML/Javascript applications right into extinction. It's
always been a shaky idea to use documents to host applications and
after more than a decade, we've got developers who "hate" Javascript,
refusing to learn it at all, and users who disable it whenever
possible as it gets in the way of reading documents. It seems only
incompetence keeps it going (most sites break when Javascript is
disabled.)

Thomas Allen

unread,
Mar 30, 2009, 2:22:36 PM3/30/09
to

Dude, I was just asking for help with a specific JavaScript problem,
not a rant filled with douchebaggery. You'll notice that never once
did I ask anybody to approve of my library choice. I actually do know
my way around JavaScript fairly well, and the main reason that I use
jQuery is for its selectors. My specialty is front-end code,
specifically cross-browser compatible, semantic CSS, and I'm a
perfectionist when it comes to my markup.

I disagree with you that selecting elements by class name is a bad
idea, rather, I think that using IDs makes no sense when they are
pretty much a crippled version of the "class" attribute. IDs make a
false pretense of uniqueness and can't be grouped (i.e. class="slow
slideshow"). Classes are a much better source of metadata about the
element(s). Using only classes (obviously, using only IDs would be a
terrible ID) also eliminates a horde of silly CSS bugs involving the
wrong CSS selector (# vs .).

I don't understand why people have to drag their opinions in when
someone's just looking for some technical help...and your
unfamiliarity with a library's API is no reason to ditch the library.
$.fn.attr is very easy to understand.

So, all that being said, I much prefer $('.sponsors') to a complicated
series of for loops that aggregate an element collection. Sure, I
could write my own getElementsByClassName (or wait for its full
adoption in browsers), but that's the point of using a library. And
even that method wouldn't support the rich set of selectors that the
major JavaScript libraries do.

Your comment about performance is a red herring: I'm not too worried
about performance in a tiny script that rotates the sources of nine
images into a target image.

Thomas

David Mark

unread,
Mar 30, 2009, 2:55:09 PM3/30/09
to

Never mind what you were doing, dude.

> not a rant filled with douchebaggery. You'll notice that never once

Are you such a douche-bag that you refuse to stop using the attr
method (or jQuery as a whole), despite the myriad downsides and no
upside? Was my explanation of the Broken as Designed code lacking?
The fact that John Resig himself *still* can't understand the
difference between attributes and DOM properties (MS is in the same
club), after three years of patching, doesn't give you pause? Go
through your app and count how many times you are calling this
obviously botched function. You are likely tangling it up with - each
- calls as well (see another recent thread.)

> did I ask anybody to approve of my library choice. I actually do know

What led you to choose it? Are you now married to it?

> my way around JavaScript fairly well, and the main reason that I use

The f--- you do (and therein lies the root of the problem.)

> jQuery is for its selectors.

jQuery doesn't have any selectors.

> My specialty is front-end code,

Your specialty is writing bullshit code (and whining apparently.)

> specifically cross-browser compatible, semantic CSS, and I'm a
> perfectionist when it comes to my markup.

Howls of derision, you then slather 50K of junk code (plus your own
junk) on top it? In other words, you paint a masterpiece and then
take crayons to it?

And do you have any finished products to back up your assertions of
competence?

[snip confused nonsense about CSS]

>
> I don't understand why people have to drag their opinions in when someone's just looking for some technical help...and your

You could have stopped with "I don't understand." And you do need
help. My help wasn't good enough?

> unfamiliarity with a library's API is no reason to ditch the library.
> $.fn.attr is very easy to understand.

You just don't get it. *You* do not understand the API. I've already
explained what it does (and it ain't pretty.) Can you? If not, what
gives you confidence in it?

>
> So, all that being said, I much prefer $('.sponsors') to a complicated
> series of for loops that aggregate an element collection.

I already told you that your design started on the wrong page.

> Sure, I
> could write my own getElementsByClassName (or wait for its full
> adoption in browsers), but that's the point of using a library.

You don't need it. See above.

> And even that method wouldn't support the rich set of selectors that the
> major JavaScript libraries do.

You don't need a "rich set of selectors" and there is no such thing as
a "major library." If you refer to Resig's botched attempts at
generalized Javascript, what do you do with these elements once you
have queried them? "Chain" them to attr calls? See the other thread.

>
> Your comment about performance is a red herring: I'm not too worried

None of this is the slightest bit mysterious (unless you are
completely clueless about browser scripting.)

> about performance in a tiny script that rotates the sources of nine
> images into a target image.

But your tiny script requires a huge script to "work." The huge
script adds nothing but complications and mistakes and changes over
time as well. (!) Did you explain this to your client or did you
promise to "write less code, save more money, etc."

A slide show is a very simple script to write and will work in
anything (and last forever) if done properly. It's been done to
death, so you should be able to find lots of examples. Of course, you
will need to learn browser scripting to weed out the bad ones. A good
indicator of a bad one is jQuery, Mootools, etc. (what you refer to as
"major libraries.")

Thomas Allen

unread,
Mar 30, 2009, 3:06:56 PM3/30/09
to
> ...
>
> read more »

I really shouldn't continue, because you clearly prefer to insult
rather than teach, but I'm dying to hear your explanation for classes
as an identifier being poor design.

Also, cutting quotes short is a show of _extremely_ poor manners. I'll
paste it here in case your browser has an 80-char width limit with
nowrap or something:

> Your comment about performance is a red herring: I'm not too worried about performance in a tiny script that rotates the sources of nine images into a target image.

David Mark

unread,
Mar 30, 2009, 3:12:55 PM3/30/09
to

Interesting take, CSS is OT here and your assertions about classes and
identifiers make no sense anyway.

>
> Also, cutting quotes short is a show of _extremely_ poor manners. I'll

[snip]

David Mark

unread,
Mar 30, 2009, 3:42:18 PM3/30/09
to

That's one of the browser sniffing versions, which has been abandoned
as even John Resig knows it is junk at this point. He took yet
another Mulligan with 1.3 (and two more since.)

The ignorant can roll their eyes all they want. Their heads will
follow.

Thomas Allen

unread,
Mar 30, 2009, 3:59:06 PM3/30/09
to
And still no answer as to why using classes instead of IDs is poor
design. I'm genuinely interested, and if anybody else here has an
answer, please offer it, as I'd prefer the non-abusive version.

Thanks,
Thomas

David Mark

unread,
Mar 30, 2009, 4:14:33 PM3/30/09
to
On Mar 30, 3:59 pm, Thomas Allen <thomasmal...@gmail.com> wrote:
> And still no answer as to why using classes instead of IDs is poor
> design.

Should be quite obvious in this case. This is the design decision
that sent you running for jQuery in the first place.

> I'm genuinely interested, and if anybody else here has an
> answer, please offer it, as I'd prefer the non-abusive version.

If you dislike abuse, don't crack out of turn. You don't know what
you are doing, refuse to listen to those who do and use words like
"douchebaggery." What did you think that would buy you here?
Furthermore, what do you think it will buy you in the long run?

Thomas Allen

unread,
Mar 30, 2009, 4:21:06 PM3/30/09
to

Dude, you let off a lengthy, insulting rant to some very benign posts
of mine because you got in a tissy because someone might want to
leverage a JavaScript library. It was an unmitigated act of
douchebaggery, and I identified it as such. I may be no expert at
JavaScript, but I do have a pretty good idea of what I'm doing; my
lack of expertise is a good reason to lean on well-tested code written
by others.

And still no explanation for preferring IDs over classes. Do you have
one?

David Mark

unread,
Mar 30, 2009, 4:34:34 PM3/30/09
to
On Mar 30, 4:21 pm, Thomas Allen <thomasmal...@gmail.com> wrote:
> On Mar 30, 4:14 pm, David Mark <dmark.cins...@gmail.com> wrote:
>
> > On Mar 30, 3:59 pm, Thomas Allen <thomasmal...@gmail.com> wrote:
>
> > > And still no answer as to why using classes instead of IDs is poor
> > > design.
>
> > Should be quite obvious in this case.  This is the design decision
> > that sent you running for jQuery in the first place.
>
> > > I'm genuinely interested, and if anybody else here has an
> > > answer, please offer it, as I'd prefer the non-abusive version.
>
> > If you dislike abuse, don't crack out of turn.  You don't know what
> > you are doing, refuse to listen to those who do and use words like
> > "douchebaggery."  What did you think that would buy you here?
> > Furthermore, what do you think it will buy you in the long run?
>
> Dude, you let off a lengthy, insulting rant to some very benign posts

Stop calling me "dude."

> of mine because you got in a tissy because someone might want to

A what?

> leverage a JavaScript library. It was an unmitigated act of
> douchebaggery, and I identified it as such. I may be no expert at

So "douchebaggery" is any point or points that makes you feel less
confident about your skills as a programmer. Get used to it. And pay
attention unless you want to end up on the wrong side of a cash
register at Radio Shack.

> JavaScript, but I do have a pretty good idea of what I'm doing; my
> lack of expertise is a good reason to lean on well-tested code written
> by others.

What a basket-case. Well-tested? Others? You didn't read anything I
posted, did you? Still waiting on your attr dissertation as well.

>
> And still no explanation for preferring IDs over classes. Do you have
> one?

Unlike the other hints I gave you, you'll have to read between the
lines on that one.

Thomas Allen

unread,
Mar 30, 2009, 4:42:16 PM3/30/09
to
On Mar 30, 4:34 pm, David Mark <dmark.cins...@gmail.com> wrote:

> Unlike the other hints I gave you, you'll have to read between the
> lines on that one.

Perhaps because you don't have an answer.

David Mark

unread,
Mar 30, 2009, 4:50:03 PM3/30/09
to

Hmmm. Maybe if you dared me to tell you.

Tim Streater

unread,
Mar 30, 2009, 6:19:09 PM3/30/09
to
In article
<29805adc-4ebe-49a8...@y13g2000yqn.googlegroups.com>,
Thomas Allen <thomas...@gmail.com> wrote:

> IDs make a false pretense of uniqueness and can't be grouped
> (i.e. class="slow slideshow").

I think you mean:

(e.g. class= ...

--
Tim

"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted" -- Bill of Rights 1689

Tim Streater

unread,
Mar 30, 2009, 6:52:37 PM3/30/09
to
In article
<f779cbce-eed1-4f15...@z9g2000yqi.googlegroups.com>,
David Mark <dmark....@gmail.com> wrote:

[loadsa stuff snipped]

I would appreciate it if you guys could:

1) top post when you only have one line to add to billyuns of others.
2) learn to snip.

Your choice.

> A slide show is a very simple script to write and will work in
> anything (and last forever) if done properly. It's been done to
> death, so you should be able to find lots of examples. Of course, you
> will need to learn browser scripting to weed out the bad ones. A good
> indicator of a bad one is jQuery, Mootools, etc. (what you refer to as
> "major libraries.")

I've never bothered with any of these libraries. And it's true that that
most issues can be researched with a little googling. For today's issue
I had to google for over an hour before finding an example I could hack
about, but this was largely a question of suitable search terms. A
couple of hours later and I have some code I can slot into my app to fix
today's problem.

I suspect the OP needs to understand what setTimeout actually does.

Richard Cornford

unread,
Mar 30, 2009, 8:32:46 PM3/30/09
to
Thomas Allen wrote:
<snip>
> ... . I actually do know my way around JavaScript fairly well, ...

I have commented before on an odd characteristic of the javascript
learning process; a tendency for people transitioning from the state of
being a complete novice to a position where they can get scripts they
'write' (read largely 'copy-paste') to do more or less 'impressive'
things in two or three web browsers, to be inflicted with a totally
unrealistic overconfidence as a result.

An illustration of the point might be:-

<URL: http://noahstokes.com/ > (Caution: this page is a choking hazard;
do not attempt to eat or drink while reading it.)

There have even been books written by people suffering that condition,
and published.

Lets be very clear about this; you do *not* know your way around
javascript fairly well. The code you have posted in this thread, along
with the question asked, scream that quite loudly enough. 6-8 months of
(hard-ish) work and you might get away with making that claim here, but
in the meanwhile that sort of BS will do you no favours.

<snip>
> ... . My specialty is front-end code, specifically cross-browser
> compatible, ...
<snip>

This newsgroup's subject is javascript, with a strong bias towards its
application in scripting web browsers for the Internet, so that
describes quite a number of the contributors to this group. But I know
that you would not even stand a chance of passing the technical test for
my job.

This may all come across as quite harsh, but it has a purpose; that
unrealistic overconfidence can stand as quite a barrier to moving
forward and with so much ground still to cover it is best discarded
earlier rather than later.

Richard.

Erwin Moller

unread,
Mar 31, 2009, 4:03:19 AM3/31/09
to

Hi Thomas,

[Please don't qoute signatures. Any good newsreader will do that for you
automagically.]


> I know, but I felt that this was a more JavaScript-oriented question.

I see others have pointed out already JQuery is not considered (good)
JavaScript by many developers. (But it is JavaScript of course.)
David Mark, the one you are having a not-so-friendly discussion with,
actually took the time to study JQuery (different versions) quite
thoroughly and he published his results in here earlier.
His findings, plus what other people I respect in comp.lang.javascript
think about JQuery, plus my own programming experience and natural
paranoid, gives me a very clear picture of JQuery: stay away from it.

Bottomline: I still cannot help you with your problem. Your simplified
version is still based on JQuery and I have no clue how JQuery's
internals work. :-/
Sorry I cannot be of help. Maybe try a JQuery forum I suggested earlier.

Good luck.

Regards,
Erwin Moller

PS: a little reflection if I may:
I can imagine you feel frustrated now. You have a problem, you post a
friendly message and ask for help.
Then people in here tells you to loose JQuery first, a lib you like,
before they can/will help.
But for your own sake: take a little distance, don't make it personal,
and look at the problem again: A lot of experienced JavaScript
developers advise you to avoid JQuery. Maybe this is actually good advise?
Why don't you roll your own full JavaScript instead? I always do that
and it gives me a lot of satidfaction when a difficult job is done right
by me in 'pure' JavaScript/DOM (no libs). Do you really need JQuery?
With a little study you can start doing all DOM manipulation yourself.
That way you will also be able to debug a lot better than now.

Erwin Moller

unread,
Mar 31, 2009, 4:04:38 AM3/31/09
to
Tim Streater schreef:

> In article
> <f779cbce-eed1-4f15...@z9g2000yqi.googlegroups.com>,
> David Mark <dmark....@gmail.com> wrote:
>
> [loadsa stuff snipped]
>
> I would appreciate it if you guys could:
>
> 1) top post when you only have one line to add to billyuns of others.
> 2) learn to snip.
>
> Your choice.

I strongly suggest the second. Topposting is a bad habbit IMHO. ;-)
It destroys the chronological order of the discussion.

Gregor Kofler

unread,
Mar 31, 2009, 8:41:03 AM3/31/09
to
Am Mon, 30 Mar 2009 11:22:36 -0700 schrieb Thomas Allen:


> Dude, I was just asking for help with a specific JavaScript problem, not
> a rant filled with douchebaggery. You'll notice that never once did I
> ask anybody to approve of my library choice. I actually do know my way
> around JavaScript fairly well, and the main reason that I use jQuery is
> for its selectors. My specialty is front-end code, specifically
> cross-browser compatible, semantic CSS, and I'm a perfectionist when it
> comes to my markup.

You're joking, right? Your claim of "knowing JS fairly well" combined
with your choice of library (plus this very problem, which is a cinch in
plain library-less JS) just don't make any sense.

> I don't understand why people have to drag their opinions in when
> someone's just looking for some technical help...and your unfamiliarity
> with a library's API is no reason to ditch the library. $.fn.attr is
> very easy to understand.

So how come when everything is so simple and easy, that you've a problem
(which again isn't one, since it can be dealt with perhaps a dozen of
lines of JS)?

> So, all that being said, I much prefer $('.sponsors') to a complicated
> series of for loops that aggregate an element collection.

One could - if supported - use document.getElementsByClassName(). My
fallback solution is precisely 6 lines of code.

> Sure, I could
> write my own getElementsByClassName (or wait for its full adoption in
> browsers), but that's the point of using a library. And even that method
> wouldn't support the rich set of selectors that the major JavaScript
> libraries do.

What do I need all those selectors for? I recently thought about doing my
"universal" selector function. But then I realized, that I've never
really needed one yet.

> Your comment about performance is a red herring: I'm not too worried
> about performance in a tiny script that rotates the sources of nine
> images into a target image.

And you are not too worried about using a 100k script for rotating 9
image sources?
Since you use a rather bloated library (you most likely don't
understand), you can't influence the performance, anyway. And if you've
more complicated tasks at hand or an iPhone as platform you just gonna
have to live with the poor performance.

Gregor


--
http://www.gregorkofler.com
http://web.gregorkofler.com - vxJS, a JS lib in progress

Gregor Kofler

unread,
Mar 31, 2009, 8:45:30 AM3/31/09
to
Am Tue, 31 Mar 2009 01:32:46 +0100 schrieb Richard Cornford:

> <URL: http://noahstokes.com/ >

Thanks for sharing. Looks like ...er... pretty aggressive marketing.

Laurent vilday

unread,
Mar 31, 2009, 11:43:26 AM3/31/09
to
Thomas Allen :

> I much prefer $('.sponsors') to a complicated
> series of for loops that aggregate an element collection.

Event delegation (google it) is a much more interesting alternative to both.

--
laurent

Dr J R Stockton

unread,
Mar 31, 2009, 9:04:48 AM3/31/09
to
In comp.lang.javascript message <24469ef9-9347-4c0f-ad70-49431a393659@k2
g2000yql.googlegroups.com>, Mon, 30 Mar 2009 12:42:18, David Mark
<dmark....@gmail.com> posted:

>Lines: 155

>That's one of the browser sniffing versions, which has been abandoned
>as even John Resig knows it is junk at this point. He took yet
>another Mulligan with 1.3 (and two more since.)
>
>The ignorant can roll their eyes all they want. Their heads will
>follow.

Read FAQ, 1.3, 2, 1.

Thomas Allen : I advise you to sign yourself in full, to reduce risk of
confusion with TL. He's the one who DM emulates.

--
(c) John Stockton, nr London UK. replyYYWW merlyn demon co uk Turnpike 6.05.
Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html> -> Timo Salmi: Usenet Q&A.
Web <URL:http://www.merlyn.demon.co.uk/news-use.htm> : about usage of News.
No Encoding. Quotes precede replies. Snip well. Write clearly. Mail no News.

David Mark

unread,
Mar 31, 2009, 1:36:05 PM3/31/09
to
On Mar 31, 9:04 am, Dr J R Stockton <reply0...@merlyn.demon.co.uk>
wrote:

> In comp.lang.javascript message <24469ef9-9347-4c0f-ad70-49431a393659@k2
> g2000yql.googlegroups.com>, Mon, 30 Mar 2009 12:42:18, David Mark
> <dmark.cins...@gmail.com> posted:

>
> >Lines: 155
> >That's one of the browser sniffing versions, which has been abandoned
> >as even John Resig knows it is junk at this point.  He took yet
> >another Mulligan with 1.3 (and two more since.)
>
> >The ignorant can roll their eyes all they want.  Their heads will
> >follow.
>
> Read FAQ, 1.3, 2, 1.

Would it have been a good idea?

>
> Thomas Allen : I advise you to sign yourself in full, to reduce risk of
> confusion with TL.  He's the one who DM emulates.

Try to pay attention, Doc. The other Thomas and I rarely agree on
anything and he certainly doesn't have my style.

Laurent vilday

unread,
Mar 31, 2009, 1:58:49 PM3/31/09
to
Dr J R Stockton :

> Thomas Allen : I advise you to sign yourself in full, to reduce risk of
> confusion with TL. He's the one who DM emulates.

I strongly disagree. I usually don't care about bashing and bird names,
but I can't let you say such thing, that's not honest.

David is *not* emulating at all Thomas Lhan. TL is an ass, David is
*not*, at least as far I can tell of course since I don't know him
personnaly.

David can seem a little rude, that's true and I even had a few
unfortunates words with him - words I regret since he was right once
again -. But he is mostly (if not always) right, his points are always
correct, he is a *very* valuable source of informations and thinking.

You (anyone) can dislike him, that's individual judgement and can't be
discussed, however you can not deny his huge javascript value.

My javascript skills (if any) have really improved since I read him. I
wish I was half competent as he is, and fuck away anyone who is too
intolerant to understand what he is saying.

David has to be listened by everyone, while TL has to be reduced to silence.

DM != TL

My 2 useless cents :)

--
laurent

Alan Gutierrez

unread,
Mar 31, 2009, 3:08:08 PM3/31/09
to
On Mar 30, 11:26 am, Thomas Allen <thomasmal...@gmail.com> wrote:
> Here's a simpler alternative:
>
> (function($) {
>         $(document).ready(function() {
>                 var sponsors = $('.sponsors');
>                 var sponsor_images = sponsors.find('img').remove();
>                 var sponsor_frame = $('<img>');
>
>                 for(var i = 0; i < sponsor_images.length; i++) {
>                        setTimeout("sponsor_frame.attr('src', $(sponsor_images[i]).attr
> ('src'))", 3000);
>                 };
>                 sponsors.html(sponsor_frame);
>         });
>
> }) (jQuery);
>
> However, I don't understand scope inside ofsetTimeout: I get

> "undefined" errors for all of the variables in thesetTimeoutcommand,
> and I'm not too keen on making each one global.

Thomas

From https://developer.mozilla.org/en/DOM/window.setTimeout

timeoutID = window.setTimeout(code, delay);

timeoutID is the ID of the timeout, which can be used with
window.clearTimeout.

The problem with your first attempt, is that you used setTimeout as if
it was a "future" pattern that would return the value returned from
your function.

The problem with your second attempt is that you are giving setTimeout
some code to run, but that means that the code will be run in the
context of the window, with the this pointer set to the window.

You want to pass a function, so that the context is captured in the
function.

But, what you really want to do is change those images after an
interval, so use setInterval.

var count = 0;
setInterval(function () {
sponsor_frame.attr('src', $(sponsor_images[count]).attr('src'));
if (++count == sponsor_images.length) count = 0;
}, 3000);

Untested. But on the right track.

Alan Gutierrez

David Mark

unread,
Mar 31, 2009, 3:24:44 PM3/31/09
to
On Mar 31, 1:58 pm, Laurent vilday <mok...@mokhet.com> wrote:
> Dr J R Stockton :
>
> > Thomas Allen : I advise you to sign yourself in full, to reduce risk of
> > confusion with TL.  He's the one who DM emulates.
>
> I strongly disagree. I usually don't care about bashing and bird names,
> but I can't let you say such thing, that's not honest.

[snip]

The good "doctor" sees Lahn everywhere. He's been obsessed with the
subject since around 2001 IIRC. I wasn't here back then, but I
stumbled over an old post once that gave me an extreme sense of deja
vu (something about Usenet posting conventions of course.) Other than
the occasional xenophobic rant and time/date musings, it's all he
talks about and the archive has preserved his personality (or lack
thereof) for posterity.

Garrett Smith

unread,
Mar 31, 2009, 4:42:18 PM3/31/09
to
David Mark wrote:
> On Mar 31, 1:58 pm, Laurent vilday <mok...@mokhet.com> wrote:
>> Dr J R Stockton :

[...]

>
> The good "doctor" sees Lahn everywhere. He's been obsessed with the
> subject since around 2001 IIRC. I wasn't here back then, but I
> stumbled over an old post once that gave me an extreme sense of deja
> vu (something about Usenet posting conventions of course.) Other than
> the occasional xenophobic rant and time/date musings, it's all he
> talks about and the archive has preserved his personality (or lack
> thereof) for posterity.

That's not true. There are a lot of posts about the FAQ that helped
contribute to changing the FAQ. Many of the items in the original FAQ
seemed to originate from him. An earlier edition of the toFixed example,
and others, from six or seven years back, appeared in a post.

He asks questions about dom-related things from time to time.

Garrett

David Mark

unread,
Mar 31, 2009, 6:00:37 PM3/31/09
to

Ah yes, numbers too.

>
> He asks questions about dom-related things from time to time.
>

He should go back to doing that.

Mike Duffy

unread,
Mar 31, 2009, 9:39:38 PM3/31/09
to
Laurent vilday <mok...@mokhet.com> wrote in
news:49d259d9$0$20347$426a...@news.free.fr:

> .... TL is an ass, David is *not*, at least as far


> I can tell of course since I don't know him personnaly.

Do you know TL personally?

I hazard coming to his defence. But although he seems too abrupt for most
people (some more than others as has been pointed out), I find that his
advice is usually correct in terms of fact.

> David can seem a little rude, that's true and

> even had a few unfortunates words with him - words
> I regret since he was right once again -. But he is
> mostly (if not always) right, his points are always correct,
> he is a *very* valuable source of informations and thinking.

This is what I see from TL, except change "little rude" to "more than a
little too rude for some people to handle". Maybe I'm just to thick-skinned
to pick up all of it. (Some may say too "thick", but I digress...)

Erwin Moller

unread,
Apr 1, 2009, 3:59:19 AM4/1/09
to
Dr J R Stockton schreef:

> In comp.lang.javascript message <24469ef9-9347-4c0f-ad70-49431a393659@k2
> g2000yql.googlegroups.com>, Mon, 30 Mar 2009 12:42:18, David Mark
> <dmark....@gmail.com> posted:
>
>> Lines: 155
>
>> That's one of the browser sniffing versions, which has been abandoned
>> as even John Resig knows it is junk at this point. He took yet
>> another Mulligan with 1.3 (and two more since.)
>>
>> The ignorant can roll their eyes all they want. Their heads will
>> follow.
>
> Read FAQ, 1.3, 2, 1.
>
> Thomas Allen : I advise you to sign yourself in full, to reduce risk of
> confusion with TL. He's the one who DM emulates.
>

I don't agree with that.
Thomas Lahn and David Mark have very different styles and are not alike.
If Thomas has a bad day he can be rude (especially to newbies), or even
insulting to some.
On good days, however, Thomas takes the time to explain difficult stuff
in-depth in long postings that surely cost him time.
It is my impression that David has (a little) more patience with
(arrogant) newbies.

Above all: Thomas Lahn and David Mark are both valuable sources of
information and reflection when it comes to JavaScript, and that is why
I participate in this group: to learn and to help others.
Posting-style is of much less importance (to me).
Maybe my skin is thick too. ;-)

Just my 2 cent.

Dr J R Stockton

unread,
Apr 1, 2009, 8:30:19 AM4/1/09
to
In comp.lang.javascript message <gqtv7e$pnt$1...@nntp.motzarella.org>, Tue,
31 Mar 2009 12:42:18, Garrett Smith <dhtmlk...@gmail.com> posted:

>That's not true. There are a lot of posts about the FAQ that helped
>contribute to changing the FAQ.

Yes.

>Many of the items in the original FAQ seemed to originate from him.

Completely untrue. Has exaggerated truth if by "original" you mean
merely before you became FAQ maintainer, or before Randy Webb did.

> An earlier edition of the toFixed example, and others, from six or
>seven years back, appeared in a post.

Jim Ley wrote that, IIRC - but possibly as a consequence of what I had
written.

FAQ 5.1 code is still not executable.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036)

0 new messages