graduate Posted January 25, 2012 Share Posted January 25, 2012 How to create a bare clean object with no prototype? Link to comment Share on other sites More sharing options...
Ingolme Posted January 25, 2012 Share Posted January 25, 2012 I don't understand what you mean. Everything in Javascript has a prototype. A bare object would be: var a = new Object(); It's going to inherit everything that's in the Object()'s prototype. Link to comment Share on other sites More sharing options...
graduate Posted January 25, 2012 Author Share Posted January 25, 2012 I don't want to inherit standard .toString() and other functions. I want the object to be perfectly clean. Link to comment Share on other sites More sharing options...
Ingolme Posted January 25, 2012 Share Posted January 25, 2012 I guess you'll have to make a new type of object for that.I can't be sure this will work for all browsers: function BareObject() { this.toString = null; this.constructor = null; this.toLocaleString = null; this.valueOf = null; this.hasOwnProperty = null; this.isPrototypeOf = null; this.propertyIsEnumerable = null;}var a = new BareObject(); But why do you want an object without a prototype? I can't imagine any situation where you would need it. You can always override any methods you want to. Link to comment Share on other sites More sharing options...
graduate Posted January 25, 2012 Author Share Posted January 25, 2012 I got it. Object.create(null) Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.