Closed vjeux closed 12 years ago
Good idea - I was thinking of adding a few standard console commands, such as dir( object ) which would do an inspection of it, and could stringify JSON.
Definitely this should be an optional thing, though. If we wanted to get really smart, could definitely implement something like the way Chrome does > Object
with a click-to-inspect thing.
You could also try JSON.stringify(object, 0, 4)
Well I don't really believe that anyone would ever want to show [object Object], so a dir
function might be overkill. Something like that would probably better imo:
Sandbox.display_object = function (obj) {
var str = obj.toString();
if (typeof obj !== 'string' && str === '[object Object]') {
str = JSON.stringify(obj, null, 4);
}
// Your display code ...
};
You probably could also do the same for arrays as well.
Yeah, that could work - I'll play around with it and see how I get on. Thanks!
Working this into the next release. Got ~30 hours of flying to do in the next 48 but will push it up in a few days!
Thanks.
From my perspective, looks like this issue was resolved in commit adbe33b
If you are interested in cross-browser support, you might want to consider using Crockford's json2.js instead of relying on browser own JSON object.
Thanks
Good call. I'll have a think about including json2 but it already has a large number of dependencies - what's more likely is including a basic stringification method of its own as part of the backbone model, like jsconsole.com does.
Instead of
That would be great to show