Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: "Christoph M. Becker" Newsgroups: comp.lang.javascript Subject: Re: What is this inside a function? Date: Sun, 07 Jun 2015 21:19:49 +0200 Organization: solani.org Lines: 24 Message-ID: <55749955.4050107@arcor.de> References: <55745377$0$12997$c3e8da3$5496439d@news.astraweb.com> <878ubvjqgp.fsf@bsb.me.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Trace: solani.org 1433704789 22620 eJwNysEBwEAEBMCWOBZbTkL0X8Jl3gMLjU4PhGOxJcVW33l8E3Zc2IUPLwek5tDkf1lUNs5eCewQPQ== (7 Jun 2015 19:19:49 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Sun, 7 Jun 2015 19:19:49 +0000 (UTC) User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 To: Ben Bacarisse X-User-ID: eJwNysERgEAIA8CWDCGg5ZBz6L8E3feKhTqdpUqt9r2Sm3ZEDR/AkG8cWhvTf9gmMsuepogPFmoQuQ== In-Reply-To: <878ubvjqgp.fsf@bsb.me.uk> Cancel-Lock: sha1:Cf3ovV/evkYIYfblMXPAoYLXd6w= X-NNTP-Posting-Host: eJwNyNEVADEEBMCasBblXBz9l5C8+Rs3CjtAJ3yfz2UOJm1+WaArwiQL+p5pIa2UiY1UnJoLDz8QWg== Xref: csiph.com comp.lang.javascript:28032 Ben Bacarisse wrote: > Steven D'Aprano writes: > >> Constructors are just functions, except they implicitly return "this", >> right? > > Not really. Constructors are just functions and they can return > whatever they like, and when called without new, they return that value. > It's the new expression that returns the new object, probably modified > by the function that was called. The value the function returns is > ignored in a new expression. The latter is only true if a primitive value would be returned. If, however, the return statement's expression evaluates to an object, this very object is returned. E.g. function foo() {return {bar: "baz"}} new foo // => {bar: "baz"} Cf. . -- Christoph M. Becker