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


Groups > comp.lang.javascript > #23559

Re: class needs to initialize vars, set data structure

Path csiph.com!usenet.pasdenom.info!goblin2!goblin.stu.neva.ru!newsfeed1.swip.net!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail
Content-Type text/plain; charset="UTF-8"
Message-ID <6465521.OizMrxDySb@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Reply-To Thomas 'PointedEars' Lahn <cljs@PointedEars.de>
Organization PointedEars Software (PES)
Date Wed, 12 Mar 2014 03:34:11 +0100
User-Agent KNode/4.11.5
Content-Transfer-Encoding 8Bit
X-Face %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&.<b';Md8`dH6iqhT)6C^.Px|[=M@7=Ik[_w<%n1Up"LPQNu2m8|L!/3iby{-]A+#YE}Kl{Cw$\U!kD%K}\2jz"QQP6Uqr],./"?;=4v
Face iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEXTxa4RFk5dUWANED8PFEfy7+MGBiW+n3ZNF/QuAAACaElEQVQ4jVXUwVOcMBQG8Dc7Rc4PUntdWV2uxjDpGaGeozOp1woar4jd5t/v9wLstMwsA/ntlxdCAgUc1hjTc9/JCZfGoo3wG3HdmdAWrIJRHe7GM/TmpY5VFefuVcAkkPbLIaN8rmPmjloyZxgyR3GuJ4K0AGtJ2htz8o7yqikm759fldQXaMpbDzjKAG+8v+AugVTOPO5DOjLvGtUYQwh0CPjnVMyGd+8/GfUB5nLKJDD2aLDh5HYyMDJGDwQIo2ZmZcKbowNmAdB/AzyFhrmF2MHRb0QJJfaAnwGB6orZhoykLzJtGwF/xpYxI1dswomiUj3gTuAIqCn/4C7cULwGNBtwMTk3Y4LfKB5YUaOKBKYtpplm7u0vip8tU1NWWyI/7XdcSuIDoMt6rVHMWT0DbjHPGqDqZVSa6zleLcUTcIKLoMv3ueJluALtAo9B302zPPlrtiVScRdCjXvVh3e3JpYa/jjkuC9N+LrBMlz/eAN4eQijX2EdLo6c5tGGHwLyHFtXk89dDGHwCVhG9T0S/j55AhRZgkMCmUQXJ49TnS1wnQDvw0eAh9ICeMmEFbCnPMFzjAvsWoEWEFdYEx+S0MoUZ1gT1wId8+AF3Bl2OoEu906AUHx5VLw/gXYg/x84loOah/2UYNrgiwSwGO7RfUzVBbx/kgpckumGOi6QirtD6gkLTitbnxNol47S2jVc2vsN5kPqaAHT8uUdAJM4v/DanjYOwmUjWznGfwB7sGtAtor5BgofDuzaRj4kSQAqDakTsKORa3Q3xKi3gE1fhl71KRMqrdZ2AWNNg/YOhQyrVBnb+i+nEg4bsDA+egAAAABJRU5ErkJggg==
Subject Re: class needs to initialize vars, set data structure
Newsgroups comp.lang.javascript
References <972c7156-b68b-4ff4-8d82-55f00676b1a7@googlegroups.com> <return-20140312004838@ram.dialup.fu-berlin.de> <set-20140312005707@ram.dialup.fu-berlin.de>
MIME-Version 1.0
Lines 75
NNTP-Posting-Date 12 Mar 2014 03:34:22 CET
NNTP-Posting-Host 7193f1a8.newsspool1.arcor-online.net
X-Trace DXC=4R6Xn=Uck;TE47KDAk81NWic==]BZ:af^4Fo<]lROoRQnkgeX?EC@@PeQ4FNC@f86[DZm8W4\YJN\YUVHKH;GI^W<_e=dZX<SRW=BJegL9gn9_
X-Complaints-To usenet-abuse@arcor.de
Xref csiph.com comp.lang.javascript:23559

Show key headers only | View raw


Stefan Ram wrote:

> ram@zedat.fu-berlin.de (Stefan Ram) writes:
>> var Set = function()

Note that, according to the latest working draft, ECMAScript Edition 6 is 
going to define a Set object type, so it is wise to test whether “Set” 
already exists before redefining it.

<https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set>

>> { var map = {};
>>  return
>>  { add     : function( element ){ map[ element ]= true; },

This breaks existing properties because the prototype chain of Object 
instances is _not_ empty; they inherit from the object referred from 
Object.prototype (the Object prototype [object]).

>>    remove  : function( element ){ delete map[ element ]; },

This could delete built-in non-inherited properties.

>>    contains: function( element ){ return map.hasOwnProperty( element );

This would consider built-in non-inherited properties.

>>    },
>>    count   : function( element ){ return Object.keys( map ).length; }

This would count only enumerable own properties, contradicting .contains().

>>    }};

This would return an Object instance from a constructor call where a Set 
instance would be expected.

Compare <http://PointedEars.de/wsvn/JSX/trunk/map.js>.
 
>   The style above, I sometimes call »module style«.
>   Usually I will prefer the style below, which I sometimes call »prototype
>   style«:
> 
> function Set(){ this.map = {}; }
> Set.prototype.add      = function( element ){ this.map[ element ]= true;
> };
> Set.prototype.remove   = function( element ){ delete this.map[ element ];
> }; Set.prototype.contains = function( element ){ return
> this.map.hasOwnProperty( element ); };
> Set.prototype.count    = function( element ){ return Object.keys( this.map
> ).length; };

The latter style that you prefer not only is tedious to write, both styles 
are also less efficient than others.  Granted, the latter style is more 
compatible than the above, but only if you consider implementations older 
than 16 years to be still relevant.  Other than that, it has no obvious 
advantages, but it has less obvious disadvantages.  BTDT.

<http://PointedEars.de/es-matrix/?filter=%7B>

Also, a set is _not_ a map, and vice-versa.  A set is a data structure that 
contains no duplicate *values*; a map is a data structure that contains no 
duplicate *keys*.

Your ongoing delusions of grandeur speaking from your postings are tiresome 
to say the least; it would be acceptable if you acquired a significant 
amount of humility.  Rest assured that your preferences and terminology are 
largely irrelevant to readers as you are evidently not experienced enough to 
serve as an authority on this topic.

-- 
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 | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

class needs to initialize vars, set data structure JRough <janis.rough@gmail.com> - 2014-03-11 15:36 -0700
  Re: class needs to initialize vars, set data structure Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-03-12 03:34 +0100
    Re: class needs to initialize vars, set data structure Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-03-12 15:09 +0100
    Re: class needs to initialize vars, set data structure John Harris <niam@jghnorth.org.uk.invalid> - 2014-03-12 17:04 +0000
      Re: class needs to initialize vars, set data structure John Harris <niam@jghnorth.org.uk.invalid> - 2014-03-14 10:48 +0000
  Re: class needs to initialize vars, set data structure Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-03-12 03:17 +0000
    Re: class needs to initialize vars, set data structure Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-03-12 11:46 +0100
    Re: class needs to initialize vars, set data structure Christoph Michael Becker <cmbecker69@arcor.de> - 2014-06-25 22:51 +0200
      Re: class needs to initialize vars, set data structure Christoph Michael Becker <cmbecker69@arcor.de> - 2014-06-26 00:42 +0200
        Re: class needs to initialize vars, set data structure Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-06-26 11:16 +0200
        Re: class needs to initialize vars, set data structure Christoph Michael Becker <cmbecker69@arcor.de> - 2014-06-26 21:44 +0200
          Re: class needs to initialize vars, set data structure John Harris <niam@jghnorth.org.uk.invalid> - 2014-06-27 09:46 +0100
            Re: class needs to initialize vars, set data structure Scott Sauyet <scott.sauyet@gmail.com> - 2014-06-28 21:57 -0700
  Re: class needs to initialize vars, set data structure Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-03-12 15:34 +0100

csiph-web