Hello, I found prototype and I was really excited about it. However a friend of mine advice me to dont use it, and give this URL to me: http://blog.metawrap.com/blog/WhyIDontUseThePrototypejsJavaScriptLibrary.aspx What do you think about it? Is there any way to avoid this "incompatibility" with existent JS code in my web app? Is prototype a good way to do things only if you wanna make your app from 0? Regards, R.R. Libera --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Hey, astecomm a écrit :> What do you think about it? Is there any way to avoid this > "incompatibility" with existent JS code in my web app? Is prototype a > good way to do things only if you wanna make your app from 0?I''m in a rush, so very shortly: - This article is 1.5 years old - Prototype hasn''t extended Object.prototype since version 1.4.0 - Extending Array.prototype is no problem at all, the issue stems from people misusing for...in: - thinking it''s a shortcut for numerical loop, which it is not; - using Array objects as associative arrays when they should use raw Object instances instead. So yeah, you should totally go with Prototype if all that holds you back is those critics. The Object one is very much obsolete, and the Array one is ill-founded. JM2C, -- Christophe Porteneuve aka TDD tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
> 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.> > Regards, > > R.R. LiberaJonathan -- Jonathan Weiss http://blog.innerewut.de --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On 6/29/07, astecomm <astecomm-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hello, > > I found prototype and I was really excited about it. However a friend > of mine advice me to dont use it, and give this URL to me: > > http://blog.metawrap.com/blog/WhyIDontUseThePrototypejsJavaScriptLibrary.aspx > > What do you think about it? Is there any way to avoid this > "incompatibility" with existent JS code in my web app? Is prototype a > good way to do things only if you wanna make your app from 0?"incompatibility" isn''t entirely true from that post. The blogger is relying on the for..in loop to go through the hash - but he never checks to ensure that the object he''s looping through has the property. Let me demonstrate: Object.prototype.extraProp = "washington"; var sample = { city:"Detroit", state:"Michigan" }; //will alert ''city'', ''state'', ''extraProp'' for (var a in sample) { alert(a); } The more reliable (although more verbose) method to loop through the object is this: //will alert ''city'',''state'' for (var a in sample) { if (sample.hasOwnProperty(a)) { alert(a); } } Making sure that the object possesses the property prior to acting on it will ensure that anything "prototyped" onto the Object object will be happily ignored when looping through your hash. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
> using "for ... in" to iterate through arraysis considered poor practice. Well, the for...in loop iterates over properties... so using it to iterate over the members of an array is just using the wrong tool for the job. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On Jun 29, 8:50 am, astecomm <astec...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello, >[snip]> > What do you think about it? Is there any way to avoid this > "incompatibility" with existent JS code in my web app? Is prototype a > good way to do things only if you wanna make your app from 0? > > Regards, > > R.R. LiberaI find it funny that the author would write something like this : "So I simply had to reject prototype.js because, out of the box, the very first time I tried to use it - it snuck out and cut the throat of the JavaScript I was using that relied on performing a for(x in object) on the contents of an Array." Because, from my perspective, you do not adopt a javascript library for only a small part of it. To be more precise, of course you will run into code refactoring when you start using a new library in a project. This is not wanted, but the library often provides simpler ways to perform a task you already defined. The for...in loop is an example. And especially with Javascript, adopting a coding style will play an important role when extending, debugging, and refactoring scripts. Personally, I think it was about time that a community based framework was developped for Javascript. And it is somehow ironic, because Prototype provides an API to do exactly what the author of that blog is whining about ; offer an abstraction layer over all those non- standard browser implementations of the ECMAScript specifications. And in my opinion, I think Prototype is complete enough to use it by itself in a project. Though I extended the API myself a little, I mostly concentrate on JS injections and Web components. Now, if only all browsers would implement CSS in a standard way ! As a final note, I once considered another Web2.0-like library which has plenty of plugins and extensions : JQuery (http:// jquery.com/) ...and guess what ? It IS compatible with Prototype. But while both libraries have the same functionalities, they aproach the DOM differently. My advice, for a project, is to choose a good and active library, one you''re the most confortable with, stick with it, and avoid adopting multiple coding style. Some people like YUI (http:// developer.yahoo.com/yui/), but I don''t. It doesn''t make it a bad framework. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On Jun 30, 3:42 am, tobie <tobie.lan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > using "for ... in" to iterate through arrays > > is considered poor practice. > > Well, the for...in loop iterates over properties... so using it to > iterate over the members of an array is just using the wrong tool for > the job.It isn''t really an issue where all the code in a page is written by the same team, it is more likely to be a problem where code is mixed from different development teams or sources. There is rarely a need to use for..in with an Array and, as you say, it is generally considered bad practice. But the fact remains that it is perfectly legal to do so and there are a small number of cases where it is a good idea - sparse arrays in matrix calculations and where the properties of both Object and Array[1] are required in the same object are two. You can also use hasOwnProperty and propertyIsEnumerable methods to determine whether the property is on the object or on the prototoype chain. Even if you think you''ll never have a problem with extended built-in objects, it is good to be aware of the fact that some of them have been extended even if only to know that there are some extra methods available and the need to avoid obvious traps. Also, to know not to add your own method that will clash with some already provided method. 1. Noting that javascript Arrays are Objects and there are other ways to solve this particular issue. -- Rob --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---