<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div class=""><br>
<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
* better way to define default constructors:<br>
class Point {<br>
num x;<br>
num y;<br>
num z;<br>
// Syntactic sugar for setting z and x before the constructor body runs.<br>
Point(this.z, this.x){...}<br>
}<br>
This is more explicit and flexible than D's way for default struct constructors,<br>
which can only allow to set all fields in order, without skipping some, and<br>
doesn't allow to do anything else in the ctor.<br>
</blockquote>
<br></div>
D doesn't allow non-trivial default struct constructors for some good reasons, which are a long discussion we've had many times. These reasons don't apply to javascript.<br></blockquote><div><br></div><div>I don't recall this syntax 'Point(this.z, this.x){...}' ever being discussed; can you please provide a link?</div>
<div><br></div><div>* it avoids the following common bug:</div><div><br></div><div>struct Point{int x;int y;}</div><div>auto a=Point(1,2,3); </div><div>//later on we add a field: struct Point{int x; int a; int y; } </div>
<div>//woops!</div><div><br></div><div><div>* less boilerplate / more DRY / more explicit:</div></div><div><br></div><div><div>struct Point{</div><div>Foo x=32;</div><div>Bar y;</div><div>Baz z;</div><div>this(this.y, this.z){} //instead of this(Bar y, Baz z){this.y=y;this.z=z;}<br>
</div><div>}</div></div><div><br></div><div><br></div><div>This is arguably a preferable syntax.</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div> </div></div></div></div>