Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #28037
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: What is this inside a function? |
| Date | 2015-06-08 01:08 +0200 |
| Organization | PointedEars Software (PES) |
| 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> |
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