Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #28032
| From | "Christoph M. Becker" <cmbecker69@arcor.de> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: What is this inside a function? |
| Date | 2015-06-07 21:19 +0200 |
| Organization | solani.org |
| Message-ID | <55749955.4050107@arcor.de> (permalink) |
| References | <55745377$0$12997$c3e8da3$5496439d@news.astraweb.com> <878ubvjqgp.fsf@bsb.me.uk> |
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
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