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

Popular posts from this blog

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -