Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I got the answer from a coworker. He's not on SO so I'm posting on his behalf and will buy him a beer the next time we are in the same city:</p> <p>Class.refactor doesn't work on Natives (Element, Array, String, etc.) because they aren't Classes nor can they be overrided to be; MooTools just adds some cool prototypes to make them more Class-like and fun and easy to work with.</p> <p>The way to extend natives is to use the implement() method; The only problem is that this.parent() and this.previous() don't exist, so you have to get a bit trickier to extend existing methods without rewriting them:</p> <hr> <pre><code>(function(){ // Keeps the window namespace clean var old_hide = Element.prototype.hide; var old_show = Element.prototype.show; Element.implement({ hide: function() { result = old_hide.run(arguments, this); // Calls old method alert("Hiding " + this.get('tag') ); return result; }, show: function(display) { result = old_show.run(arguments, this); // Calls old method alert("Showing " + this.get('tag') ); return result; } }); })(); // Closes the private function and executes it immediately </code></pre> <hr> <p>The key concepts here are:</p> <p>1 - Encapsulate the whole shebang in a private, self-executing function so the global namespace isn't polluted by our variable assignments for the original methods (e.g. old_hide and old_show);</p> <p>2 - Use the Native object's implement() method to override each function, much like you had done as the second argument to Class.refactor;</p> <p>3 - Instead of calling this.parent() or this.previous() in each method, you call the old prototypes using MooTools' run() method, which passes the arguments with a binding to the function and executes it.</p> <p>As before, make sure to gather the result of the function.run() call and return it to maintain API consistency.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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