Whenever I type console.log/console.dir on an object, one of the properties that always shows up is __proto__ which is the constructor.
is there any way to hide this?
Whenever I type console.log/console.dir on an object, one of the properties that always shows up is __proto__ which is the constructor.
is there any way to hide this?
Hiding the __proto__ is not worth it! (see below why)
var old_log = console.log;
console.log = function ()
{
function clearProto(obj)
{
if (obj && typeof(obj) === "object")
{
var temp = JSON.parse(JSON.stringify(obj));
temp.__proto__ = null;
for (var prop in temp)
temp[prop] = clearProto(temp[prop]);
return temp;
}
return obj;
}
for (var i = 0; i < arguments.length; ++i)
arguments[i] = clearProto(arguments[i]);
old_log.apply(console, arguments);
}
var mixed = [1, [2, 3, 4], {'a': [5, {'b': 6, c: {'d': '7'}}]}, [null], null, NaN, Infinity];
console.log([1, 2, 3], mixed);
old_log([1, 2, 3], mixed); // 4 comparison (original mixed has __proto__)
NaN and Infinity can't be cloned with JSON. In Chrome you also get the line-number on the right side of the dev tools. By overriding console.log you'll lose that. Not worth to hide __proto__ over that one!