Object has Object.toString
, a method that you can call on any object. When iterating through the property list, or, just doing a console.log(obj), you will not see toString come up as a property of an object. It is hidden.
I want to add a new method on to the Object primitive, using Object.prototype.myMethod. I do not however want it to come up every time I iterate through an object. I would like it hidden.
How can I do that?
You can do that with ECMAScript 5's
defineProperty
[docs]:Obviously this does not work in browsers that don't support ES5 (especially IE8 and earlier).