Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #28037
| 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 | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
| Newsgroups | comp.lang.javascript |
| Subject | Re: What is this inside a function? |
| Date | Mon, 08 Jun 2015 01:08:31 +0200 |
| Organization | PointedEars Software (PES) |
| Lines | 44 |
| Message-ID | <1622672.QCbqgxkKEs@PointedEars.de> (permalink) |
| References | <55745377$0$12997$c3e8da3$5496439d@news.astraweb.com> <878ubvjqgp.fsf@bsb.me.uk> <55749955.4050107@arcor.de> |
| Reply-To | Thomas 'PointedEars' Lahn <cljs@PointedEars.de> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="UTF-8" |
| Content-Transfer-Encoding | 8Bit |
| X-Trace | solani.org 1433718672 7704 eJwFwYEBwDAEBMCVKvxjnCL2HyF3UArbjaBhsdSR2W/lwHzyjrb/4NnYBMoyuuTWKQ4RGQ8fExEe (7 Jun 2015 23:11:12 GMT) |
| X-Complaints-To | abuse@news.solani.org |
| NNTP-Posting-Date | Sun, 7 Jun 2015 23:11:12 +0000 (UTC) |
| User-Agent | KNode/4.14.2 |
| X-User-ID | eJwNy0kBwDAIBEBLEG45hC3+JTT/GRNnn1A3V1tbOVUnk8PguHO5pTBUm1p9ngsICe2H9sK+3CY9pmhhUP4/1hU5 |
| Cancel-Lock | sha1:41NIhmNEtY7PeWSmdjdvY3YYkKM= |
| X-NNTP-Posting-Host | eJwFwYEBwDAEBMCVEP90HEX2HyF3OFR2OEHHxd0NmVQyrHOGrYoV1Il/aV5bXpKWnJWCfg8cdRD6 |
| Xref | csiph.com comp.lang.javascript:28037 |
Show key headers only | View raw
Christoph M. Becker wrote:
> […] If […] 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"}
Should be “function Foo” and “new Foo”, respectively. JSHint is able to
point that out with {newcap: true}, but the check will be moved to the
JavaScript Code Style checker (JSCS) with the next major JSHint release:
<http://jshint.com/docs/options/#newcap> p.
> Cf. <http://ecma-international.org/ecma-262/5.1/#sec-13.2.2>.
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 <http://PointedEars.de/wsvn/JSX/trunk/object.js>.
--
PointedEars
FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix>
Please do not cc me. / Bitte keine Kopien per E-Mail.
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