Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!news.swapon.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Ben Bacarisse Newsgroups: comp.lang.javascript Subject: Re: What is this inside a function? Date: Sun, 07 Jun 2015 20:43:15 +0100 Organization: A noiseless patient Spider Lines: 28 Message-ID: <87wpzfi9t8.fsf@bsb.me.uk> References: <55745377$0$12997$c3e8da3$5496439d@news.astraweb.com> <878ubvjqgp.fsf@bsb.me.uk> <55749955.4050107@arcor.de> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="017616aa25f81ec581c44d76d61ba2f3"; logging-data="18655"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19ahPBDZXEKsIZ6S7c0XFU1JPYy8GAHArs=" Cancel-Lock: sha1:xSwNxWOlxp60gP4SEi3kljFGRg8= sha1:CS/7xvqw+az0MgnFk3Y3gd9L7EE= X-BSB-Auth: 1.533cbdd5db1c4c582909.20150607204315BST.87wpzfi9t8.fsf@bsb.me.uk Xref: csiph.com comp.lang.javascript:28033 "Christoph M. Becker" writes: > 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. . Ah, yes, I forgot that. Thanks. -- Ben.