Michael Winter wrote:[color=blue]
> On 12/03/2006 19:48, pinti wrote:[color=green]
>> "Jonas Raoni" [wrote]:[color=darkred]
>>> Do not prototype the Array nor the Object,[/color][/color]
>
> If adding a method or property to the prototype object of either is the
> best solution, then do it.[/color]
I don't see a good reason to to this. Sure it looks prettier, but in my
opinion it's a high price for damaging the language =/
[color=blue][color=green][color=darkred]
>>> by doing it you damage the "for..in" loop, [...][/color][/color]
>
> That statement is so rarely needed that it's hardly an argument.
> Besides, if all that's being added is functions then those additions can
> be screened out.[/color]
It doesn't matter if it's not used often, there are a lot of things that
I don't use often, but this isn't an excuse to kill it. If you can avoid
breaking the language by just passing an extra argument, why not?
If someone add new code that use such loops, they will break because you
were worried about prettifying the code =]
[color=blue][color=green]
>> Array.prototype.in_array = function (value) {
>> for (var hoba in this)
>> if (this[hoba] == value) return true;[/color][/color]
I think the "===" would be a better operator.
[color=blue]
> Unless you expect your arrays to be large and sparse, use a 'regular'
> for statement and loop through the numeric properties bounded by the
> length property.[/color]
I agree, the for..in loop is quite fast under Flash, but on JavaScript
it's slow and useful only for cycling through object properties.
[color=blue][color=green]
>> (in this case, why doesn't if list all the predefined or built-in
>> Array methods?)[/color]
>
> The vast majority (perhaps all, I'm not going to check) of specified
> built-in methods (of all objects) are defined with the DontEnum
> attribute. This is a specification mechanism unavailable to user-defined
> code that prevents these methods from being enumerated using a for..in
> statement.[/color]
Yeah =]
alert([].propertyIsEnumerable("join"));
--
Now with alcohol <URL:http://youtube.com/watch?v=lnQTZxqxc10> =X
Jonas Raoni Soares Silva
http://www.jsfromhell.com