Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #31225
| From | Scott Sauyet <scott@sauyet.com> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: JSlint finds for loops intolerable |
| Date | 2016-09-03 22:47 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <nqfjto$o1c$1@dont-email.me> (permalink) |
| References | <npug18$166s$1@gioia.aioe.org> <npuldh$q9l$1@solani.org> |
Christoph M. Becker wrote:
> emf wrote:
>> In the current JSLint help webpage (http://jslint.com/help.html) it now
>> says:
>>
>> "Tolerate for statement:
>> true if the for statement should be allowed It is almost always better
>> to use the array methods instead."
[ ... ]
>> I do not understand, however, the comment about array methods. I seldom
>> find use for them. Can someone explain what Crawford implies??
>
> Instead of looping with `for` or `while` over all elements of an array,
> you can instead do:
>
> myArray.forEach(function(el) {
> ...
> });
>
> Once you get the hang of using Array.prototype.forEach(), you'll
> probably find many places where a more specific array method is more
> appropriate (for instance, .filter() and map()), and these can simplify
> the code (even more).
Indeed. This is the first thing I teach JS developers trying to move
beyond a junior level. I emphasize pure, side-effect free functions, and
once they're doing this, I point out that every `for-` and `forEach-`
loop remaining is better expressed with one of the standard functions.
> Note that this programming style is often referred to as applicative or
> functional programming. You may consider to learn about it (I can
> recommend
> <https://drboolean.gitbooks.io/mostly-adequate-guide/content/>).
I heartily concur. That's an excellent book. I'd also add Reginald
Braithwaite's _JavaScript Allongé_, either the first edition [1] or the
second, ES6/ES2015, focused one [2].
[1]: https://leanpub.com/javascript-allonge
[2]: https://leanpub.com/javascriptallongesix
-- Scott
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
JSlint finds for loops intolerable emf <emfril@gmail.com> - 2016-08-28 06:56 -0400
Re: JSlint finds for loops intolerable "Christoph M. Becker" <cmbecker69@arcor.de> - 2016-08-28 14:28 +0200
Re: JSlint finds for loops intolerable emf <emfril@gmail.com> - 2016-08-29 22:35 -0400
Re: JSlint finds for loops intolerable Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-08-30 12:11 +0200
Re: JSlint finds for loops intolerable "Christoph M. Becker" <cmbecker69@arcor.de> - 2016-09-03 20:54 +0200
Re: JSlint finds for loops intolerable Scott Sauyet <scott@sauyet.com> - 2016-09-03 23:03 +0000
Re: JSlint finds for loops intolerable Scott Sauyet <scott@sauyet.com> - 2016-09-03 22:47 +0000
Re: JSlint finds for loops intolerable Lewis Perin <perin@panix.com> - 2016-08-28 16:50 -0400
Re: JSlint finds for loops intolerable Lewis Perin <perin@panix.com> - 2016-08-28 18:49 -0400
Re: JSlint finds for loops intolerable Lewis Perin <perin@panix.com> - 2016-08-28 19:13 -0400
Re: JSlint finds for loops intolerable $Bill <news@todbe.com> - 2016-08-28 14:59 -0700
csiph-web