On Jun 29, 2007, at 7:17 AM, Jonathan Weiss wrote:

>> What do you think about it? Is there any way to avoid this
>> "incompatibility" with existent JS code in my web app?
>
> This is no longer true. Prototype used to "upgrade" several base  
> objects
> in a way that other libs could choke on it. In practise this nearly
> never happended. But again, this is no longer the case.

It's still partly true.  As the article author alleges, Prototype  
does extend the prototype object of Strings, Arrays, Functions,  
Elmements, etc.  What it no longer does is apply extensions to Object.

The "for ... in" syntax will work when used on objects (this was  
fixed quite a while ago)--it will create less desirable results when  
used on Arrays. However, using "for ... in" to iterate through arrays  
is considered poor practice, particularly by Prototype  
programmers ... :)

So long as you (or your library) avoids the use of "for ... in"  
except when referring to objects (sometimes referred to in other  
languages as "associative arrays" or "hash tables") and object  
properties, you'll be fine.  This implies you'll properly use Arrays  
for numerical arrays, and Objects/hashes when you need non-numeric or  
non-sequential keys.

Most mature libraries avoid these pitfalls already.  The only one  
that keeps showing up on this list is the json library from json.org  
(it extends the Object prototype, like Prototype used to), but that  
functionality is now built in to Prototype.  (It's time like this I  
wish Sam would have picked a different name.)

I used it successfully, but I admittedly use Scriptaculous (designed  
for use w/ Prototype) and very few other add-on libraries.

I hope that helps to answer your question.


TAG

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to