Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>To make this work you need to capture the _super method while in the subclassed method, like this:</p> <pre><code>dance: function(){ // capture the super method for later usage var superMethod = this._super; window.setTimeout(function(){ return superMethod(); },50); }; </code></pre> <p>The reason this works, and your code does not, is that the <code>extend()</code> method in inherit.js captures the superclass' method as <code>this._super</code> right before your overridden method is run. It then runs your code, and after your code has run it restores _super to whatever it was set to before it ran. The action takes place in the following bit of code from inherit.js</p> <pre><code> var tmp = this._super; // Add a new ._super() method that is the same method // but on the super-class this._super = _super[name]; // The method only need to be bound temporarily, so we // remove it when we're done executing var ret = fn.apply(this, arguments); this._super = tmp; return ret; </code></pre> <p>So to be more specific; when the original code was run, the function that was used as a parameter to setTimeout was bound to the original object. The reason it did not work was that, even though <code>this</code> referenced the right object, <code>this._super</code> referenced something else, since <code>this._super</code> was reset to point to whatever it pointed to before the method was run. Probably it was not set, so the value of <code>this._super</code> was most likely just <code>undefined</code>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload