Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!news.unit0.net!takemy.news.telefonica.de!telefonica.de!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail Content-Type: text/plain; charset="UTF-8" Message-ID: <3504411.n7x7zaDXQ0@PointedEars.de> From: Thomas 'PointedEars' Lahn Reply-To: Thomas 'PointedEars' Lahn Organization: PointedEars Software (PES) Date: Wed, 12 Mar 2014 15:34:20 +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+&. MIME-Version: 1.0 Lines: 41 NNTP-Posting-Date: 12 Mar 2014 15:34:22 CET NNTP-Posting-Host: ad526190.newsspool2.arcor-online.net X-Trace: DXC=UN=e]3XZD7ZE47KDAk81NWA9EHlD;3YcR4Fo<]lROoRQ8kF ram@zedat.fu-berlin.de (Stefan Ram) writes: >> function Set(){ this.map = {}; } > > Next version: > > function Set(){ this.map = Object.create( null ); }; This makes the “map” property public, allowing everyone to mess with the set. It also requires an implementation of ECMAScript Edition 5 or later, or an emulation of Object.create(). > Set.prototype = > { add : function( element ){ this.map[ element ]= true; } , > remove : function( element ){ delete this.map[ element ]; }, > contains : function( element ){ return element in this.map; }, Again, these work reliably only for String values where the value is not the name of a *non-inherited* built-in property, or for non-String values where the string representation of the value is no such name. > count : function( element ){ return Object.keys( this.map ).length; > }}; This would prevent the methods from being created on each invocation of Set(), however it overwrites the existing “prototype” property so that the “constructor” property of the object referred to from the “prototype” property value refers to the same object as “Object”, not as “Set” (because it now refers to an Object instance). It also allows everyone to mess with the methods because they are public. Instead of bothering everyone with your repetitions of common mistakes, you should read previous discussions before you post, and follow-ups to your postings more carefully. And RTFM, RTFFAQ, STFW. -- PointedEars FAQ: | SVN: Twitter: @PointedEars2 | ES Matrix: Please do not Cc: me. / Bitte keine Kopien per E-Mail.