Path: csiph.com!weretis.net!feeder4.news.weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: Thomas 'PointedEars' Lahn Newsgroups: comp.lang.javascript Subject: Re: Comparing some of the ways to create objects Date: Mon, 04 Apr 2016 22:12:45 +0200 Organization: PointedEars Software (PES) Lines: 27 Message-ID: <1773037.o7vNLfRneB@PointedEars.de> References: Reply-To: Thomas 'PointedEars' Lahn Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Trace: solani.org 1459800768 10854 eJwFwQEBACAIA7BMFzgSx6P0j+AWRrDTGfSYmAR0SmFNIRclGxyvrDFG3X1Jo9q3+uHZBxXcEQs= (4 Apr 2016 20:12:48 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Mon, 4 Apr 2016 20:12:48 +0000 (UTC) User-Agent: KNode/4.14.2 X-User-ID: eJwFwQkBwDAIA0BLPAkFOS0M/xJ2Rw+NPggGuNwWa+YqMQMajtCyMU+ftKS1C/z6JserHK46nxWS79rF/jEFFIw= Cancel-Lock: sha1:2rkKnLWICmKvy/2gREk7On2l0hg= X-NNTP-Posting-Host: eJwFwYkRwDAIA7CVyIF5ximJvf8IleB58lYkMiDI2zjTza1K3ZjzXc/gQxG+WzbCRNNE6u0PF38Riw== Xref: csiph.com comp.lang.javascript:30219 Scott Sauyet wrote: > John Harris wrote: >> It's time to compare ways of creating objects now that the full release >> version of Firefox implements class declarations. The code below shows >> three of the ways. They are all ones where an object is created by using >> new and a constructor. > > I don't see why that is so special. I will add several more suggestions > below that use three different object creation APIs, including a 'new-and- > constructor' version. Two of them also share the same sort of prototype- > based object mechanism shared by your three samples. Just a quick remark on the code of variants 2 and 3: A function declaration must not occur in a Block statement (“{…}”) if the code is to be portable (which it were in this case if the Block statement delimiters were omitted). Short version: Do not write code this way. If you need a function within a block, use a function expression (assigned to a variable) instead. See for details. -- PointedEars FAQ: | SVN: Twitter: @PointedEars2 | ES Matrix: Please do not cc me. / Bitte keine Kopien per E-Mail.