Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!feeder.erje.net!1.eu.feeder.erje.net!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: Thomas 'PointedEars' Lahn Newsgroups: comp.lang.javascript Subject: Re: What is this inside a function? Date: Fri, 12 Jun 2015 19:19:18 +0200 Organization: PointedEars Software (PES) Lines: 41 Message-ID: <1908572.Dhjy60Y1dk@PointedEars.de> References: <55745377$0$12997$c3e8da3$5496439d@news.astraweb.com> <878ubvjqgp.fsf@bsb.me.uk> <55749955.4050107@arcor.de> <1622672.QCbqgxkKEs@PointedEars.de> Reply-To: Thomas 'PointedEars' Lahn Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Trace: solani.org 1434129735 29794 eJwNxMEBwCAIA8CVhEKi4zQI+4/Q3uPygaEYSEROTit2BntGdqH+KxPOBsvWSzTovGd5lLv4ASnbEQw= (12 Jun 2015 17:22:15 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Fri, 12 Jun 2015 17:22:15 +0000 (UTC) User-Agent: KNode/4.14.2 X-User-ID: eJwNyMkNADEIBLCWMgEGUQ7H0n8Jm5clmxBsVxrV1tYLIoV8Eb3Bh7cc5HeunRJse0/kbt6B1nIYDqgNtwc/RaQVjA== Cancel-Lock: sha1:K1fn5lk+fgtOENco/W1hLO/+L3s= X-NNTP-Posting-Host: eJwFwYERACEIA7CV5KAVx/m3dP8RTJAM3l0EC4bV9JyU/injLAqaNtPpXXEX1J0D5V6lLx4xuBF6 Xref: csiph.com comp.lang.javascript:28091 Thomas 'PointedEars' Lahn wrote: > Christoph M. Becker wrote: >> Cf. . > > Correct, and this has practical implications: > > function Person2(name, age) > { > if (!(this instanceof Person2)) return new Person2(name, age); > > this.name = name; > this.age = age; > } > > and with JSX: > > function Person2(name, age) > { > if (!(this instanceof Person2)) return Person2.construct(arguments); > > this.name = name; > this.age = age; > } > > See also Function.prototype.construct() and > Function.prototype.construct2() in > . Du not bother looking for .construct2(); it went the way of the dinosaur with r510 last year already :) The new .construct() does not use eval() anymore, and as it was also superior to the .construct2() that Asen Bozhilov suggested, I have removed the latter method. -- PointedEars FAQ: | SVN: Twitter: @PointedEars2 | ES Matrix: Please do not cc me. / Bitte keine Kopien per E-Mail.