title: How to pass arguments when extending a jQuery method?
body: <p>I'm trying to modify <code>.offset()</code> so that it never returns <code>undefined</code>, i.e. for invisible/hidden elements.</p>
  
  <p>The problem that I'm having with that is that I don't know how to properly pass <code>this</code> to the original method, to be honest. Breakpoint-debugging reveals that I keep getting <code>Window</code> when it should be the element in question. Here's what I got:</p>
  
  <pre><code>(function( $ ){
    var original = $.fn.offset;
  
    $.fn.offset = function( elem, coordinates, pass ) {
      console.log('step 1');   // successful.
      console.log(this);       // element confirmation.
      var o = original(elem, coordinates, pass);  // triggers an exception.
      console.log('step 2');   // is never reached.
  
      if (o === undefined ) {
        console.log('step 3a');
        return {};
      }
      else {
        console.log('step 3b');
        return o;
      }
    }
  }( jQuery ));
  
  […]
  
  $('#element').offset();   // method call.
  </code></pre>
  
  <p>And here's the exception:</p>
  
  <pre><code>Error in event handler for (unknown): TypeError: undefined is not a function
      at jQuery.fn.extend.offset (chrome-extension://…/js/jquery-1.11.0.js:10109:10)
      at $.fn.offset (chrome-extension://…/js/jquery-modifications.js:35:11)
  </code></pre>
  
  <p>I've tried different variations – <code>original(arguments)</code>, <code>this.original()</code>, <code>original(this, …)</code> – but none worked. In <a href="https://stackoverflow.com/questions/6506156/how-to-edit-a-jquery-function">this question</a> an argument called <code>elem</code> is used next to three more arguments – but I'm not sure why. Is it because the <a href="http://api.jquery.com/attr/" rel="nofollow noreferrer">API</a> mentions <code>attributeName</code>, <code>value</code> and a callback function? If so then my attempt should work, analogous to the <a href="http://api.jquery.com/offset/" rel="nofollow noreferrer"><code>.offset()</code> API</a>. Looking at how <a href="https://code.jquery.com/jquery-1.10.2.js" rel="nofollow noreferrer">jQuery</a> defines these functions didn't help either because <code>.fn.attr</code> doesn't even show up like <code>.fn.offset</code> does.</p>