qwe*_*ymk 12 javascript debugging console google-chrome
每当我输入console.log/console.dir一个对象时,总会出现的一个属性__proto__就是构造函数.
有没有办法隐藏这个?
重新定义console.log:
console.log = function (arg) {
var tempObj;
if (typeof arg === 'object' && !arg.length) {
tempObj = JSON.parse(JSON.stringify(arg));
tempObj.__proto__ = null;
return tempObj;
}
return arg;
};
Run Code Online (Sandbox Code Playgroud)
这不会修改肯定需要__proto__的原始对象.
console.debug = function() {
function clear(o) {
var obj = JSON.parse(JSON.stringify(o));
// [!] clone
if (obj && typeof obj === 'object') {
obj.__proto__ = null;
// clear
for (var j in obj) {
obj[j] = clear(obj[j]); // recursive
}
}
return obj;
}
for (var i = 0, args = Array.prototype.slice.call(arguments, 0); i < args.length; i++) {
args[i] = clear(args[i]);
}
console.log.apply(console, args);
};
Run Code Online (Sandbox Code Playgroud)
var mixed = [1, [2, 3, 4], {'a': [5, {'b': 6, c: '7'}]}, [null], null, NaN, Infinity];
console.debug(mixed);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4693 次 |
| 最近记录: |