Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #25968

Re: when have we to use obj.hasOwnProperty(key) ?

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Newsgroups comp.lang.javascript
Subject Re: when have we to use obj.hasOwnProperty(key) ?
Date Tue, 21 Oct 2014 19:27:58 +0200
Organization PointedEars Software (PES)
Lines 39
Message-ID <2573276.tGzZJPnWE1@PointedEars.de> (permalink)
References <m25b7r$554$1@shakotay.alphanet.ch>
Reply-To Thomas 'PointedEars' Lahn <cljs@PointedEars.de>
Mime-Version 1.0
Content-Type text/plain; charset="UTF-8"
Content-Transfer-Encoding 8Bit
X-Trace solani.org 1413912479 1834 eJwFwYEBwCAIA7CXYLSI51DR/09YwkjPs5BM8PEJEW5ohZQ3ZuAxZWe4UYumkewWu/Vx2/oBHJcRGA== (21 Oct 2014 17:27:59 GMT)
X-Complaints-To abuse@news.solani.org
NNTP-Posting-Date Tue, 21 Oct 2014 17:27:59 +0000 (UTC)
User-Agent KNode/4.14.1
X-User-ID eJwFwYEBwDAEBMCVksdjnAr2H6F3Jrx8rjSqra14lgx48NXutGCFTB1xZMA2HMxTLITgGiJtsN280433AzoTFOk=
Cancel-Lock sha1:g+cYGoVfoaz4ecqkFJlLIxwrjZM=
X-NNTP-Posting-Host eJwFwYEBwCAIA7CXGNAi51iV/09YguDHU0kwMRi3sEqktI85X/lq3Ogd3v2c6wEidUVpmD8DBxCo
Xref csiph.com comp.lang.javascript:25968

Show key headers only | View raw


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.

_latter_
 
> 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 ?

It is unclear what you are asking.  However, if you want a reference to an 
object that does not inherit any properties, use

  var obj = Object.create(null);

If this method is implemented as specified, you do not have to use 
obj.hasOwnProperty() when iterating over the object's properties with a for-
in statement.

-- 
PointedEars
FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix>
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


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