On Tuesday 08 September 2009 13:56:14 Joran wrote:
> Dear Tobie
>
> Thank you for your reply. Could I suggest a few more questions?
>
> 1. Does EcmaScript 5 preclude one from modifying
> Object.prototype.toString?
>
> 2. Over-writing Object.prototype.toString does not at first glance
> appear to cause it to show up in for...in loops in Rhino, Safari or
> Firefox. This was the idea behind the suggestion, given the usual
> problems with extending Object.prototype. I have not tried other
> environments. Are there still other issues?
>
> 3. Object.toString returns "[object Object]". Surely returning more
> information than this would be no more misleading than the current
> implementation? Surely a toString method need not return a string
> which exactly describes the object but only a representation thereof?
> If point 1 above, would not a JSON representation be further along in
> the spirit of being more accurate and informative than "[object
> Object]"?
>
> ..In the interest of being able to do: Console.log('Object: ' +
> object) instead of: Console.log('Object: ' + JSON.stringify(object)).

Haven't tried it but off the top of my head you could do something like:

Console.log = Console.log.wrap( function( proceed ){
    var args = 
        $A( arguments ).collect( function( arg ){
            return arg.toString === Object.prototype.toString?  
                JSON.stringify(object) : arg;
        });
    return proceed.call( Console, args );
});

You should try the Firebug console btw, it gives an interactive, explorable 
version of the object rather than converting it to a String. In this case I 
think giving a JSON Object.toString is a problem because the console already 
gives that information anyway so now it is trying to give it twice.

-- 
Jim
my wiki ajaxification thing: http://wikizzle.org
my blog: http://jimhigson.blogspot.com/

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype: Core" group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to 
prototype-core-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to