title: How to detect the end of a method chain in JavaScript?
body: <p>Firstly and most importantly I'm trying to detect the end call of a method chain. I would also like to devise a way to detect how many methods "in" or "down" an object chain I am within my method calls in a method chain.</p>
  
  <p>For instance, in the plugin I'm writing:</p>
  
  <pre><code>var result = $("#someDiv").myPlugin.foo().bar()._foo()._bar();
  </code></pre>
  
  <p>Say the method is currently executing in .bar() I would like to know that I'm 2 methods down the chain.</p>
  
  <p>The reason I need to abstract this information in some manner is so when I reach the last method in the chain I can return a result instead of the plugin object thus breaking the chain at that point for the sake of gaining access to our data in the 'result' variable.</p>