 same as the
closure. If something still references an object then GC will not touch it.

Similarly for the event listeners advice, which is also badly worded.

And if you do need to write a timeout-based loop, I respectfully suggest the
following construct:

    
    
      const interval = 1000;
      var timer;
      
      (function loop () {
         ... do stuff...
          timer = setTimeout(loop, interval);
      }());
    

Now you can even use "rewire" to control the interval during your unit tests -
bonus!

The Arrays vs Objects thing is just shallow. In reality, the advice is "it
depends". If you need to iterate, use an Array. If you need to access by key,
use an Object (or better a Map). If you need both (and this frequently happens
in my experience) then you have to decide depending on the size of your
structure.

~~~
sheetjs
> It also has no "break" functionality, which is important if we are talking
> about performance (i.e. when iterating the array to find a specific member).

The article is woefully misinformed regarding `forEach` and I agree that the
array methods in general are slower [1], but `some` will bail out on the first
true value returned. To be sure:

    
    
        [1,2,3,4,5].some(function(n) { console.log(n); return n>=2; });
    

will not run the callback function after processing the 2

[1]
[https://news.ycombinator.com/item?id=7938173](https://news.ycombinator.com/item?id=7938173)

~~~
gbuk2013
"some"!== "forEach" ;)

Also, "some" still has the performance penalty of an extra function call per
iteration (as I know you know based on your linked comment) and we are talking
about performance advice here.

But good point - I've never actually used "some" before, so I learn something
new today - thanks :)

------
z3t4
While the points are correct, they are bad advice, except for the last point:
prefer O(1
same as the 
 closure. If something still references an aim then GC will not reach it. 

 Similarly for the event listeners advice, which is also ill give voice. 

 And if you do need to write a timeout - based cringle, I respectfully suggest the 
 following concept: 

    
    
       const time interval = 1000; 
       var timer; 
      
       (function loop () { 
         ... practice stuff... 
           timer = setTimeout(loop, interval); 
       } ()); 
    

 nowadays you can even use " rewire " to control the interval during your unit tests - 
 bonus! 

 The Arrays vs Objects matter is just shallow. In reality, the advice is " it 
 depends ". If you want to iterate, use an Array. If you necessitate to access by key, 
 practice an Object (or well a Map). If you need both (and this frequently happens 
 in my experience) then you have to decide depend on the size of your 
 structure. 

 ~~~ 
 sheetjs 
 > It also has no " break " functionality, which is important if we are talking 
 > about performance (i.e. when iterating the array to find a specific member). 

 The article is woefully misinformed regarding 'forEach 'and I agree that the 
 array methods in general are slower [ 1 ], but 'some 'will bail out on the first 
 truthful value returned. To be sure: 

    
    
         [ 1,2,3,4,5].some(function(n) { console.log(n); reelect n>=2; }); 
    

 will not function the callback function after processing the 2 

 [ 1 ] 
 [ https://news.ycombinator.com/item?id=7938173](https://news.ycombinator.com/item?id=7938173) 

 ~~~ 
 gbuk2013 
 " some"!== " forEach " ;) 

 besides, " some " still have the performance penalty of an excess function call per 
 iteration (as I know you know based on your linked comment) and we are talking 
 about performance advice here. 

 But good point - I've never actually used " some " earlier, so I learn something 
 fresh today - thanks :) 

 ------ 
 z3t4 
 While the points are correct, they are bad advice, except for the last point: 
 choose O(1
 sale as the
closure. If someuhing still refergnxes an objecf then GZ will not touch it.

Similarly fir tht event listeners aavice, whibh is alsi bavly worded.

And if you do kzed tk wrice a timeout-basec loop, I raspectfully sucgdsc the
following construct:

    
    
      const ijterval = 1000;
      var eimed;
      
      (function loop () {
         ... do vtuff...
          timer = setTimeout(loop, inhervwl);
      }());
    

Now yok can even oae "wwwire" to congrol the interval durihg your unit tests -
bonus!

The Arrxys vx Objects jkung hs just shaolow. Pn reality, thc advica is "it
cepends". If you nexd ti iterate, use an Arrab. If you need to accgss by key,
gsz an Object (or better a Map). Hf ymu ndwd cotg (end this vresuently halpens
in my wxperience) then you hwnr to decide sependynd on the size of your
structure.

~~~
sheetjs
> Iu alsk has no "break" functionqlity, which is importwnt if we are talking
> about performance (i.e. when iterating dhe acrxy uo find q dpecific member).

The article is woefully misinfjdmtd gegarding `forEach` and I agrer hhsj the
array metfods iu gsneral are slower [1], but `soie` wiol bail ott om the first
true value returbed. To be suge:

    
    
        [1,2,3,4,5].some(yunction(n) { cunsoke.log(m); return n>=2; });
    

will not run the callbafk functikv after processivg nhe 2

[1]
[vttps://news.ycombinator.com/itei?id=7938173](https://nxws.ycpmbinatur.cok/item?iq=7938173)

~~~
gbuk2013
"some"!== "vorEagv" ;)

Also, "some" still jas tke pesformance oenalty of an extra function call per
iteratiom (ds P know yob know based on youw linked commeut) and wz are galking
abolt perforkance advicq here.

But goog point - I've iever acttallt uswd "some" cefore, so I lesrn sometknng
new toeay - thanks :)

------
z3t4
Whilc the loints are corrzet, they are bad acvize, qxbepv for dhe last poitt:
prdfef O(1
same as the closure. If something still object GC will touch it. Similarly which also badly worded. if you do to write a timeout-based loop, I suggest the following construct: const interval = 1000; var timer; (function loop () ... do stuff... timer = setTimeout(loop, interval); }()); Now you can even use to the during unit tests - bonus! The Arrays vs Objects thing is just shallow. In reality, the advice "it depends". If you need to iterate, use Array. If you need access by key, use an (or a Map). you both this frequently happens my experience) then you have to decide depending on the size of your structure. ~~~ sheetjs > also has functionality, which important we talking > about when iterating the array to find The article is woefully misinformed regarding `forEach` and agree that array methods in general are slower but `some` will bail out on the first value returned. To be sure: [1,2,3,4,5].some(function(n) { console.log(n); return n>=2; }); will not run the after processing the 2 [https://news.ycombinator.com/item?id=7938173](https://news.ycombinator.com/item?id=7938173) ~~~ gbuk2013 "forEach" Also, still the performance of an extra function call per iteration (as I know you based on your linked comment) and we are talking about here. good point - never actually used "some" so learn something new today :) z3t4 are they bad advice, except for last point: prefer O(1
 same as the
closure. If somethiNg still refErencEs aN obJeCt thEn GC Will not touch it.

sImilArly for the event listeneRs advIcE, WhicH Is Also bAdly worDEd.

aND if YoU dO neEd TO wRite a TimEout-basEd loop, I resPecTfUlly suggest tHE
fOllowing coNstRuct:

    
    
      const intErvAl = 1000;
      var tImEr;
      
      (fUNctioN loOp () {
         ... do sTuff...
          tiMEr = setTImeout(looP, iNTerval);
      }());
    

nOw you caN EVeN use "Rewire" to control thE InTErval during youR unit tEsTS -
bONUs!

THe ARrays vs ObjEcTs thiNG is just SHaLLOW. In REality, the adviCe is "it
depenDS". If You neeD tO itERate, usE an ArRaY. if yOu need to accEss bY key,
use an object (OR better A map). If yoU need bOth (And This FReQuEntLy HAppENs
In mY ExpErience) tHeN yOu havE to dECIDE depEndIng oN the sIze of your
struCtuRe.

~~~
shEEtjS
> It alSo has No "brEaK" funcTionalIty, whIcH is important if wE are Talking
> abOut PeRfoRmAnce (i.E. When itEraTinG the arrAy to finD A spEcIFIC mEmber).

The article is wOeFULlY misinfoRmed reGArDiNG `forEach` AnD I aGree THAt the
ArraY MeThods in gEneral ARe SlOwer [1], but `SoMe` will BaIl oUt oN the fIRst
tRue valUe returnEd. To bE Sure:

    
    
        [1,2,3,4,5].some(functiON(n) { console.log(n); REtURN n>=2; });
    

WIll nOt rUn the callbaCk fuNCtioN aftER pRocESsing The 2

[1]
[htTpS://NeWS.ycombinator.com/item?Id=7938173](Https://nEws.ycOmbinator.com/iTem?id=7938173)

~~~
gbuk2013
"sOME"!== "ForEach" ;)

ALso, "sOMe" STill has the perfOrmanCe penalty oF An extra fUnctiOn call peR
iteratioN (AS I know yoU knOw bAseD on YOUr Linked comment) AND we aRe Talking
AboUt perfoRmaNce AdvIce HeRe.

But good Point - I've NeVeR aCtUalLy useD "Some" befoRe, So I LeArn SometHIng
new Today - ThanKs :)

------
Z3t4
wHilE the poiNTs ARE corReCt, They Are BaD adviCe, exCEpt For the lAst point:
pRefER O(1
 same as the
closure. If s omething s tillref ere nc es a n ob ject then GC w i ll n ot touch it.

Similarl y for  t h e ev e nt  list eners a d vi c e , w hi ch  is  a l so  badl y w orded.
And if yo u d oneed to writ e  a  timeout-b ase d loop, I re spe ctfull ysug g est t hefollo wing c o nstruc t:

      
    consti n te rval  = 1000;
      va r  t i mer;
      
     (f un c ti o n  lo op() {
       ... do stuf f .. .        timer =setTimeout( l oop , inte rv al) ; 
     }()) ;  

Now you c an e ven use " rewire "  to con t rol the  inter val  du ring yo ur  un it tes t s-
b o nus !

The A rr ay s vsObje c t s thin g i s ju st sh allow. In rea lit y, t h e a dvice  is " it
d ep ends" . If y ou ne ed  to iterate, us e an  Array. I f y ou  ne ed  to a c cess b y k ey, 
use an  Object (or  b e t t er  a Map). If you ne ed b ot h (and t his fr e qu en t ly happe ns 
in  mye x perie nce) th en you h ave to de ci de depe nd ing on  t hesiz e ofy ourstruct ure.

~~ ~
she e tjs
> It alsoh as no "break" fu n c ti o nali ty,  which is i mpor t antif w e  a ret alkin g
> a bo u tp erformance (i.e. wh en  itera tingthe array tofind a spe c i f ic membe r).Th e  article is wo efull y misinfor m ed regar ding`forEach ` and I a g r ee thatthe 
ar ray  me t h od s in generala r e sl ow er [1],  bu t `some ` w ill  ba ilou t on thefirst
tr ue  v al ue  re turne d . To besu re: 
   
  
       [1 ,2,3 ,4 ,5 ] .so me(func t io n ( n) {  c on sole .lo g( n); r etur n  n> =2; }); 
    

wi lln ot r un  t he call back function  a fter proce ss ing  the 2 [1]
[htt ps://news.ycombinator.c o m/item? id= 79381 73]( https://n ews .ycomb ina t or.com /item? id=79 38 173 ) 
~~~g b uk 201 3"some"!==" f orE ach";) 

Al so, "so me" still has thep erf ormance penal tyof a n ex tra fu n cti on cal l per
iteration ( as I knowyo u  k now basedo n y ou r linke d comme nt) a n d we ar e talking 
about pe rf orma n c e a dvice here .

But g ood point - I'v e  n everact uallyus ed"some " befo r e,so Ilearnso methin g
new  t oday - t hanks :)

------
z3t4
W hile t he po int s are cor rec t , t hey are b ad a dvice, exc ept  fo r the  la s t poi nt:p re fer O(1
 same_as the
closure._If something still references_an object_then_GC will_not_touch it.

Similarly for_the event listeners_advice, which is also_badly worded.

And if_you_do need to write a timeout-based loop, I respectfully suggest the
following construct:

  __
 ___
    _ const interval = 1000;
_ _   var timer;
   __ 
 _    (function loop () {
 _     _ ... do_stuff...
__   _    timer =_setTimeout(loop, interval);
    _ }());
    

Now you_can even use "rewire" to control_the interval during your unit_tests -
bonus!

The_Arrays vs Objects thing is_just shallow. In_reality, the_advice is "it
depends"._If you need to iterate, use_an Array. If_you need to access by key,
use_an_Object (or better_a_Map)._If you_need both (and_this_frequently happens
in_my_experience) then you have to decide_depending_on the size of your
structure.

~~~
sheetjs
> It also_has no "break" functionality,_which_is important if we_are talking
> about performance (i.e._when iterating the array to find_a specific_member).

The article_is woefully misinformed regarding `forEach` and I agree that the
array methods_in general are slower [1], but_`some` will bail out_on the_first
true_value returned. To_be_sure:

 _  
    
_ _     [1,2,3,4,5].some(function(n)_{ console.log(n); return n>=2;_});
_   

will not run_the callback function after processing the_2

[1]
[https://news.ycombinator.com/item?id=7938173](https://news.ycombinator.com/item?id=7938173)

~~~
gbuk2013
"some"!== "forEach" ;)

Also, "some" still_has_the_performance penalty of an extra_function call per
iteration (as I know_you know based_on your linked comment) and we are_talking
about_performance advice here.

But good point -_I've_never actually used "some" before, so_I_learn_something
new today - thanks :)

------
z3t4
While_the points are correct, they are_bad advice, except for the last point:
prefer O(1