Hey Bogdan,
BogMor a écrit :> Object.prototype.toJSONString = function () {
> ...
> }
OK, *this* is widely regarged as *evil*.
Prototype carefully avoids extending Object.prototype, since this makes
EVERY use of for/in invalid, despite its being used properly (to iterate
over object properties). This effectively disables the native JS
feature, for all intents and purposes.
You can''t just walk into EVERY SINGLE OBJECT and slap it with your
additions. You have to make that relevant to the object type.
Prototype extends Arrays, Numbers and Strings, but NOT Object (I think
it originally did, which resulted in some major shield raising).
Just don''t do that, okay? You might want to replace that with
Object-namespaced function, that is:
Object.toJSONString = function(object) {
...
}
And then, to serialize yourObj:
Object.toJSONString(yourObj)
That''s what''s done with extend, inspect, keys, values and
clone.
> for (var name in headers)
> this.transport.setRequestHeader(name, headers[name]);
Which is proper, indeed. The headers variable here is not an array, but
an internal object with property-based name/value pairs.
> for (var i = 0; i < requestHeaders.length; i += 2)
> this.transport.setRequestHeader(requestHeaders[i],
> requestHeaders[i+1]);
Yes, that was back when we used an ugly array-based scheme with
even-numbered items being names, and odd-numbered items being values.
> I think is necessary a bug fix here, because the request isn''t
executed
> in this case of functions.
It''s not a bug. It''s very much intentional. Extending
Object.prototype
breaks a whole lot of things, in most scripts, just about everywhere.
It makes for/in unworkable even in per-spec usage.
--
Christophe Porteneuve a.k.a. TDD
"[They] did not know it was impossible, so they did it." --Mark Twain
Email: 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
-~----------~----~----~----~------~----~------~--~---