Am 04.01.2006 um 00:54 schrieb Werner Punz:
Well that is the problem the alteration of object also broke the
for loop on the Array, because the basic prototype structures of every
object in the system were altered.
Similar issues could arise at other parts of the lib,
the already fixed iterate over object (and therefore iterate over
everything javascript object related) bug just was the most
prominent showcase of those issues.
Heya,
The problem here is really not Prototype extending JavaScript built-
in objects.
JavaScript is a dynamic language and you're not forbidden from
extending the
built-ins to become more programmer-friendly.
It really all boils down to one thing (let the namespaces aside for
now):
The for-in loop.
This is a language construct that iterates over all properties of an
object.
Because JavaScript is a dynamic language where you can add/change
Object prototypes at all times, this construct doesn't guarantee the
kind of
properties which are returned.
According to the ECMAScript Language Specification:
"Enumerating the properties of an object includes enumerating
properties of its prototype".
So the problem is that the for-in loop is just not used with that in
mind when
it's called upon for stuff like iterating over the elements of an array.
(sadly, the JavaScript "DontEnum" attribute can't be set manuall,
so it can't be used to mask/hide individual properties (like the
addtional functions on the Object prototype):
"DontEnum: The property is not to be enumerated by a for-in
enumeration").
IMHO, trying to not to use extensions for built-in objects (where
they really make sense,
see Prototype's Enumerables) to avoid errors because of "misinformed
programming"
in other libraries is not using the JavaScript language for what it is.
Note that even Brendan Eich, the "father of JavaScript" recommends
that if
you want extensions on built-in objects, than just do it (as it's
meant for that).
(He also acknowledges the for-in loop problem and is in favor of
adding something to the next Version
of JavaScript so you can define DontEnum properties, that won't show
in for-in loops.)
-Thomas
_______________________________________________
Rails-spinoffs mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs