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


Groups > comp.lang.javascript > #28091

Re: What is this inside a function?

From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Newsgroups comp.lang.javascript
Subject Re: What is this inside a function?
Date 2015-06-12 19:19 +0200
Organization PointedEars Software (PES)
Message-ID <1908572.Dhjy60Y1dk@PointedEars.de> (permalink)
References <55745377$0$12997$c3e8da3$5496439d@news.astraweb.com> <878ubvjqgp.fsf@bsb.me.uk> <55749955.4050107@arcor.de> <1622672.QCbqgxkKEs@PointedEars.de>

Show all headers | View raw


Thomas 'PointedEars' Lahn wrote:

> Christoph M. Becker wrote:
>> 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>.

Du not bother looking for .construct2(); it went the way of the dinosaur 
with r510 last year already :)  The new .construct() does not use eval() 
anymore, and as it was also superior to the .construct2() that Asen Bozhilov 
suggested, I have removed the latter method.

<http://pointedears.de/wsvn/JSX/trunk/object.js?op=diff&rev=510>

-- 
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


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