Allen Wirfs-Brock (2015-01-17T17:30:58.000Z)
d at domenic.me (2015-01-28T19:28:39.538Z)
On Jan 17, 2015, at 5:59 AM, Frankie Bagnardi wrote: > I'm also expecting a lot of questions about 'what is this new.target thing in this code?', 'is new a variable?', 'where does it come from?', 'isn't new an operator?', etc. as proposed, `new.target` is a MemberExpression consisting of the three token sequence `new` `.` `target` It is only allowed in function code. If the enclosing function is invoked as a call expression the value of `new.target` is null ```js (function() {assert(new.target===null)})() ``` if the enclosing function is directly invoked as a constructor via `new` the value of `new.target` is the function ```js function f() {assert(new.target===f)} new f(); ``` if the enclosing function is indirectly invoked as a constructor via `super()` or `new super()` the value of `new.target` is the function new was directly applied to ```js class Super { constructor() {assert(new.target===Sub)}} class Sub extends Super {constructor() {super()}} new Sub(); ``` > > if (this instanceof MyDate) ... > > ... is clearer, but I guess it needs to be disallowed because of the other rules. When a function is called (rather than new'ed) its `this` value is usually undefined (assuming a strict function)