Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #25963
| From | Joao Rodrigues <groups_jr-1@yahoo.com.br> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: when have we to use obj.hasOwnProperty(key) ? |
| Date | 2014-10-21 13:21 -0200 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <m25tmj$tts$1@speranza.aioe.org> (permalink) |
| References | <m25b7r$554$1@shakotay.alphanet.ch> |
On 21/10/2014 08:06, Une Bévue wrote:
> I'm using something like :
>
> var obj = {};
> obj.foo = 'bar';
>
> If I look at this object in the wrowser inspector I see :
>
> Object
> foo: 'bar'
> __PROTO__ : Object
>
> the later with a lot of methods.
>
> For the time being I never have a prob with unwanted properties, but I
> wonder if...
>
> Because this object is send to a websocket server by Json and then
> included in MongoDB database.
>
> Then does I have to filter out this object or not ?
You can use Object.create(null) to create an Object with null as
prototype. This method is supported in IE9+ and the other major
browsers. See the ES5 compatibility table by Kangax:
<http://kangax.github.io/compat-table/es5/>
var obj = Object.create(null);
obj.foo = 'bar';
console.log(obj);
On the other hand, var obj = {} is equivalent to:
var obj = Object.create(Object.prototype);
--
Joao Rodrigues
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
when have we to use obj.hasOwnProperty(key) ? Une Bévue <unbewusst.sein@fai.invalid> - 2014-10-21 12:06 +0200
Re: when have we to use obj.hasOwnProperty(key) ? Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2014-10-21 13:21 -0200
Re: when have we to use obj.hasOwnProperty(key) ? Une Bévue <unbewusst.sein@fai.invalid> - 2014-10-21 17:26 +0200
Re: when have we to use obj.hasOwnProperty(key) ? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-10-21 19:27 +0200
Re: when have we to use obj.hasOwnProperty(key) ? Une Bévue <unbewusst.sein@fai.invalid> - 2014-10-22 10:22 +0200
csiph-web