Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #20168
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!news-1.dfn.de!news.dfn.de!news.informatik.hu-berlin.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail |
|---|---|
| From | "Mel Smith" <med_cutout_syntel@aol.com> |
| Newsgroups | comp.lang.javascript |
| Subject | Re: 'pushing' vs direct array assignment ? |
| Date | Thu, 6 Jun 2013 08:54:21 -0600 |
| Lines | 55 |
| Message-ID | <b1bm4vFarahU1@mid.individual.net> (permalink) |
| References | <b14atkFk8dnU1@mid.individual.net> <a5852b36-342a-4bdd-9ad5-1a8b8cd57af9@googlegroups.com> |
| X-Trace | individual.net Ej9sAvP4PZi2j/0C/ikuQgLgB1lab9VsC4xVcmjDN00V+Gdm2I |
| Cancel-Lock | sha1:6MKlqVwSyf0ORhylTHAMx3tAiTg= |
| X-Priority | 3 |
| X-MSMail-Priority | Normal |
| X-Newsreader | Microsoft Outlook Express 6.00.2900.5931 |
| X-RFC2646 | Format=Flowed; Original |
| X-MimeOLE | Produced By Microsoft MimeOLE V6.00.2900.6157 |
| Xref | csiph.com comp.lang.javascript:20168 |
Show key headers only | View raw
Rob said:
In order to determine a preference for one method or another, it is
important to establish the criteria for evaluation. Some that might apply
(in approximate order of importance) are:
1. Unintended side effects: iterating over an array by index may create
undefined properties, but if you are creating a contiguous list from zero
then it doesn't matter.
2. Support in likely host environments: very old browsers don't support
Array.prototype.push, so if you need to support those it's better to use
direct assignment (or add a push method if feature detection shows it's
missing, which may be another question). If you use direct assignment, you
never need to worry. But there must be very few browsers on the web that
don't have push.
3. Performance: as has been noted, this goes both ways. For 1,500 items, I
suspect it won't make much difference on a modern computer, but might be
significant in the types of environments where support for push is more
likely to be lacking.
4. Maintainability (code clarity): I don't think there are any issues here
with one approach or the other.
5. Number of characters to type: direct assignment saves 3 characters, not
worth dying in a ditch over (IMHO of course).
So on balance, for code expected to be widely used on the web, I'd go with
direct assignment, but be happy with push if it was used.
Applying the above analysis to your context might give a different result.
> or, is there another preferred way to do this quickly ?
Depending on your target environment, JavaScriptâ„¢ 1.7 (released in October
2006 with Firefox 2) introduced iterators and generators[1]. But that
approach doesn't get a very high score for the support criterion if you need
to work with environments other than those compliant with JavaScriptâ„¢ 1.7.
1.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators
Hi Rob:
The above gives me much more to 'chew on' and puzzle over. Also, the
link above on 'Iterators ...' will provide substance for this evening's
reading -- The .next() function is completely new to me.
Thank you.
-Mel
Back to comp.lang.javascript | Previous | Next — Previous in thread | Find similar | Unroll thread
'pushing' vs direct array assignment ? "Mel Smith" <med_cutout_syntel@aol.com> - 2013-06-03 13:59 -0600
Re: 'pushing' vs direct array assignment ? Scott Sauyet <scott.sauyet@gmail.com> - 2013-06-03 13:39 -0700
Re: 'pushing' vs direct array assignment ? "Mel Smith" <med_cutout_syntel@aol.com> - 2013-06-03 14:46 -0600
Re: 'pushing' vs direct array assignment ? Stefan Weiss <krewecherl@gmail.com> - 2013-06-04 02:07 +0200
Re: 'pushing' vs direct array assignment ? "Mel Smith" <med_cutout_syntel@aol.com> - 2013-06-03 18:40 -0600
Re: 'pushing' vs direct array assignment ? "Mel Smith" <med_cutout_syntel@aol.com> - 2013-06-03 20:38 -0600
Re: 'pushing' vs direct array assignment ? Martin Leese <please@see.Web.for.e-mail.INVALID> - 2013-06-04 09:11 -0600
Re: 'pushing' vs direct array assignment ? "Mel Smith" <med_cutout_syntel@aol.com> - 2013-06-04 12:47 -0600
Re: 'pushing' vs direct array assignment ? Stefan Weiss <krewecherl@gmail.com> - 2013-06-04 22:44 +0200
Re: 'pushing' vs direct array assignment ? "Mel Smith" <med_cutout_syntel@aol.com> - 2013-06-04 16:02 -0600
Re: 'pushing' vs direct array assignment ? Martin Leese <please@see.Web.for.e-mail.INVALID> - 2013-06-04 20:24 -0600
Re: 'pushing' vs direct array assignment ? Gregor Kofler <usenet@gregorkofler.com> - 2013-06-05 14:50 +0200
Re: 'pushing' vs direct array assignment ? Martin Leese <please@see.Web.for.e-mail.INVALID> - 2013-06-05 22:38 -0600
Re: 'pushing' vs direct array assignment ? Tim Slattery <Slattery_T@bls.gov> - 2013-06-05 08:51 -0400
OT: Accept-Encoding (was: 'pushing' vs direct array assignment ?) Christoph Becker <cmbecker69@gmx.de> - 2013-06-05 15:23 +0200
Re: 'pushing' vs direct array assignment ? RobG <rgqld@iinet.net.au> - 2013-06-05 18:12 -0700
Re: 'pushing' vs direct array assignment ? "Mel Smith" <med_cutout_syntel@aol.com> - 2013-06-06 08:54 -0600
csiph-web