Javascript’s toSource() is fun

js> x = { "name" : 'Duck', "surname" : 'Donald' }
[object Object]

js> x.toSource()
({surname:"Donald", name:"Duck"})

js> x.f = function(i) { return i+2; }

function (i) {
return i + 2;

js> x.f(12)

js> x.toSource()
({surname:"Donald", name:"Duck", f:(function (i) {return i + 2;})})

See the reference for more info.

2 Responses to Javascript’s toSource() is fun

  1. Ioan Sameli says:

    Wow, this is useful !

    But as usual, doesn’t work on MSIE… Only good for playing.

  2. Nice. I didn’t know about that one. As Ioan mentioned, it’s too bad this does not work on IE. Thanks for the tip!

%d bloggers like this: