Hiding the __proto__ property in the Chrome console

Whenever I type console.log/console.dir for an object, one of the properties that is always displayed is __proto__ , which is the constructor.

Is there any way to hide this?

+6
source share
5 answers

Override 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 will not change the original object that __proto __ should definitely have.

+5
source
 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); }; 

 var mixed = [1, [2, 3, 4], {'a': [5, {'b': 6, c: '7'}]}, [null], null, NaN, Infinity]; console.debug(mixed); 
+3
source

Use Object.create(null) to create objects without __proto__

If you just want to hide the proto displayed on objects with .__proto__ on the console, you cannot. Although I do not understand why you want.

Btw, .__proto__ is not an object constructor, but a link [[Prototype]] .

0
source

Use Opera and Dragonfly . In the settings (script tab), you can uncheck the option "Show prototypes".

0
source

Although .__proto__ important, obviously there is a way to hide things from the console. This is demonstrated when trying to do:

  for (var i in function.prototype) { console.log(i+": "+function.prototype[i].toString()) } 

There will be some things that are not logged into the console, and I think this is exactly what this topic is about (IMO answers should allow all prototypes so that anyone who visits this section can use it).

Also: __proto__ not a constructor. This is the object of the object with the highest priority. It is important that you do not remove proto and do not leave it alone, because if there is a method that uses JavaScript, then it all comes to shit. For the constructor, look obj.constructor , it is not a screw with all the damn thing, and it could just be what he called, constructor, imagine that.

0
source

Source: https://habr.com/ru/post/922168/


All Articles