Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
419 views
in Technique[技术] by (71.8m points)

javascript - 在Chrome的控制台中隐藏__proto__属性(hiding the __proto__ property in Chrome's console)

Whenever I type console.log/console.dir on an object, one of the properties that always shows up is __proto__ which is the constructor.(每当我在对象上键入console.log/console.dir时,总是显示的属性之一就是__proto__ ,它是构造函数。)

is there any way to hide this?(有什么办法可以隐藏这个吗?)

  ask by qwertymk translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Redefine console.log:(重新定义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;
};

This won't modify the original object which definitely needs to have __proto__.(这不会修改绝对需要__proto__的原始对象。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...