javascript - Is there a way to hide Object.prototype's property? -


if add property object.prototype object.prototype.sth = "something";

then, there way hide property specified object? tried this:

function foo() { // sth... } foo.prototype = null; var bar = new foo(); 

however, bar still have access property sth;


bar.__proto__ = null or foo.prototype.__proto__ = null works

i think way is:

  function foo() {          this.sth = null // or this.sth = undefined;     }      var bar = new foo(); 
  • foo.prototype = null;: bar.__proto__ point directly object.prototype.
  • without foo.prototype = null;: bar.__proto__ point foo.prototype, , foo.prototype.__proto__ points object.prototype

another way:

function foo() { // sth... } foo.prototype.sth = undefined; //or foo.prototype.sth = null; var bar = new foo(); 

Comments