User:Jresig/JavaScript 2 Gotchas

  • Revision slug: User:Jresig//JavaScript_2_Gotchas
  • Revision title: User:Jresig/JavaScript 2 Gotchas
  • Revision id: 179510
  • Created:
  • Creator: Jresig
  • Is current revision? No
  • Comment /* <tt>override</tt> is required for overriding inherited items */

Revision Content

<tt>override</tt> is required for overriding inherited properties

Consider the following (incorrect) example:

 class Artist {
   function draw(){}
 }
 
 class Designer extends Artist {
   function draw(){ /* ... new draw ... */ }
 }

The above will throw the following error (in the reference implementation):

 **ERROR** DefnError: illegal override of [ns public ]::draw  (near <no filename>:1:48-1.49)

You'll just to make sure that any functions or properties that you override from a base class that you properly mark with 'override', like so:

 class Artist {
   function draw(){}
 }
 
 class Designer extends Artist {
   override function draw(){ /* ... new draw ... */ }
 }

Revision Source

<h3 name="override_is_required_for_overriding_inherited_properties"> <tt>override</tt> is required for overriding inherited properties </h3>
<p>Consider the following (incorrect) example:
</p>
<pre class="eval"> class Artist {
   function draw(){}
 }
 
 class Designer extends Artist {
   function draw(){ /* ... new draw ... */ }
 }
</pre>
<p>The above will throw the following error (in the reference implementation):
</p>
<pre class="eval"> **ERROR** <b>DefnError: illegal override</b> of [ns public <i>]::draw  (near &lt;no filename&gt;:1:48-1.49)</i>
</pre>
<p>You'll just to make sure that any functions or properties that you override from a base class that you properly mark with 'override', like so:
</p>
<pre class="eval"> class Artist {
   function draw(){}
 }
 
 class Designer extends Artist {
   override function draw(){ /* ... new draw ... */ }
 }
</pre>
Revert to this revision