I think you're saying the same thing in different ways.

I believe Rob is saying that the similarities between array syntax  
and one way of using object syntax (i.e. square brackets) are similar  
enough to be confusing if a programmer doesn't understand the  
difference.

I know you know this, Thomas, but I'm going to go through it anyway  
for those still learning.

Take this object/hash for example:

var ob1 = {a: 1, b:2};

It's clear to us that the most appropriate way to access the  
properties are ob1.a and ob.2.  But consider this object:

var ob2 = {'a+2': 2, 'Hello, world': 3);

We can't access the properties as "ob2.a+2"  That gives us something  
other than what we want.  It is appropriate in this instance to use  
the square bracket notation:

ob2['a+2'] += 1;

Just because we're using square brackets doesn't mean we're dealing  
with an array.



TAG

On Jun 2, 2007, at 10:47 AM, Thomas Fuchs wrote:

> Am 31.05.2007 um 02:09 schrieb RobG:
>
>> While using an Array like a plain Object is considered bad coding
>> style in general, there is nothing wrong with it in terms of syntax -
>> it doesn't break any part of the ECMAScript specification - and there
>> are situations where it can be considered the right thing to do.
>
> No, there is not. You're iterating over the properties of the object,
> not the items of the array. It's not the syntax that's broken, it's
> just plain and clearly wrongly used.
>
> Anyway, removing the automatic extension of all arrays will certainly
> break Prototype from functioning correctly, as it uses arrays
> internally too, and expects them to be extended.
>
> The big thing is: If you have legacy JavaScript code: now it's a good
> time to rewrite it, with concise and readable Prototypish syntax and
> unit tests to boot. :)
>
> Best,
> Thomas


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