adding the long-ago-needed documentation for constructors with 'return this'

This commit is contained in:
Jeremy Ashkenas
2010-02-26 20:09:49 -05:00
parent 93f644fae2
commit 723ea53585
2 changed files with 12 additions and 0 deletions

View File

@@ -611,6 +611,12 @@ coffee --print app/scripts/*.coffee > concatenation.js</pre>
the immediate ancestor's method of the same name.
</p>
<%= code_for('super', true) %>
<p>
<b>A cautionary note:</b> JavaScript allows you to return a different value from
a constructor function, ignoring the newly-created object. In CoffeeScript,
it's best practice to always return <tt>this</tt> as the last line of a
constructor, as seen above.
</p>
<p>
<span id="pattern_matching" class="bookmark"></span>

View File

@@ -1279,6 +1279,12 @@ tom = new Horse("Tommy the Palomino");
sam.move();
tom.move();
;'>run</button><br class='clear' /></div>
<p>
<b>A cautionary note:</b> JavaScript allows you to return a different value from
a constructor function, ignoring the newly-created object. In CoffeeScript,
it's best practice to always return <tt>this</tt> as the last line of a
constructor, as seen above.
</p>
<p>
<span id="pattern_matching" class="bookmark"></span>