Hello Fred, Fred a écrit : > A good suggestion, but there are circumstances where using for..in with > an array makes sense.
Agreed, but just how border-case are those? The sparse array example you provide is good, but extremely seldom, and architecturally debatable: who wants massive number-crunching in JS? > If you are using multiple libraries, you should have a strong > preference for those that don't modify built-in objects. This, again, is debatable. Here's my POV: the only reason prototype extension (as long as it doesn't break behavior of the prototype's standard properties) might be a problem is for/in loops, AFAIK. On the other hand, prototype extension is, admittedly, key to leveraging the power of JS. That's what prototypes are *for*. Most of the really powerful libraries out there rely on prototype extension, which makes for faster, more concise code than vanilla procedural code. And JS 1.7+ follows this trend, going further towards "programming in the large", introducing iterators, array comprehensions, and the like. > I think you have that backwards - libraries that modify built-in > objects don't play well with code that expects those objects to be > unadulterated. See? POV :-) If built-in objects were not supposed to be extended, they wouldn't have accessible prototypes. Same goes for DOM objects (but this outside of standard JS scope, it's more of a browser maker's choice). Especially in the Rails world, stemming from a language like Ruby where *no class is ever closed*, you can expect people to extend existing objects as they see fit. That could be frowned upon if they broke these object's inherent behaviors. They generally don't. However, the whole reason for this discussion is the for/in loop, which is used here mostly as syntactic sugar for array loops, a usage that is definitely *not* its primary purpose. And as we saw, the advantages of such a loop over a vanilla numerical one are few and far between. I hope I'm not feeding a troll here. Were I, let's avoid feeding it too much further then, this group has been blissfully exempt of those so far. 'best, -- Christophe Porteneuve a.k.a. TDD "[They] did not know it was impossible, so they did it." --Mark Twain Email: [EMAIL PROTECTED] --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
