screenlog.js icon indicating copy to clipboard operation
screenlog.js copied to clipboard

Objects log incorrectly

Open Mat-thieu opened this issue 10 years ago • 3 comments

Whenever I log an object all I get is

[object Object]

I fixed this myself by adding this code on line 30

for (var i = arguments.length - 1; i >= 0; i--) {
    if(typeof arguments[i] == 'object' && !Array.isArray(arguments[i]))
        arguments[i] = JSON.stringify(arguments[i]).replace(/"/g, "").replace(/,/g, ', ').replace(/:/g, ': ');
};

This is obviously not the best way to fix this issue, but the use of JSON.stringify might save you some headaches.

This happens in chrome(46.0.2490).

Mat-thieu avatar Nov 23 '15 09:11 Mat-thieu

Yes, its on the list. But for now, as mentioned in the example also, you can simple use JSON.stringify.

eg. console.log(JSON.stringify(obj))

chinchang avatar Nov 23 '15 09:11 chinchang

@chinchang Aah, my apologies, I think I read over that part :)

Mat-thieu avatar Nov 23 '15 09:11 Mat-thieu

We can't use JSON.stringify to convert circular structures.

JSON.stringify(window)

princejwesley avatar Nov 23 '15 23:11 princejwesley