Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #28032

Re: What is this inside a function?

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" <cmbecker69@arcor.de>
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> (permalink)
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 <ben.usenet@bsb.me.uk>
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

Show key headers only | View raw


Ben Bacarisse wrote:

> Steven D'Aprano <steve@pearwood.info> 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. <http://ecma-international.org/ecma-262/5.1/#sec-13.2.2>.

-- 
Christoph M. Becker

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

What is this inside a function? Steven D'Aprano <steve@pearwood.info> - 2015-06-08 00:21 +1000
  Re: What is this inside a function? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-06-07 19:58 +0100
    Re: What is this inside a function? "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-06-07 21:19 +0200
      Re: What is this inside a function? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-06-07 20:43 +0100
      Re: What is this inside a function? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-06-08 01:08 +0200
        Re: What is this inside a function? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-06-12 19:19 +0200
    Re: What is this inside a function? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-06-07 23:48 +0200

csiph-web