title: How to define generic methods in node.js?
body: <p>In node.js I struggle with classes/objects and the 'this' keyword.  E.g:</p>
  
  <pre><code>function Set(arr,leq) {
    this.leq = leq ? leq : function(x,y) {return x&lt;=y;};
    this.arr=arr.slice().sort(this.geq);
  }
  Set.prototype.geq=function(x,y) { return this.leq(y,x);}
  
  var myset = new Set([1,5,3,2,7,9]);
  
  
  TypeError: Object #&lt;Object&gt; has no method 'leq'
  at [object Context]:1:47
  at Array.sort (native)
  at new Set ([object Context]:3:22)
  at [object Context]:1:13
  at Interface.&lt;anonymous&gt; (repl.js:171:22)
  at Interface.emit (events.js:64:17)
  at Interface._onLine (readline.js:153:10)
  at Interface._line (readline.js:408:8)
  at Interface._ttyWrite (readline.js:585:14)
  at ReadStream.&lt;anonymous&gt; (readline.js:73:12)
  </code></pre>
  
  <p>However, if I remove the <code>.sort</code> fragment like this:</p>
  
  <pre><code>function Set(arr,leq) {
    this.leq = leq ? leq : function(x,y) {return x&lt;=y;};
    this.arr=arr.slice();
  }
  </code></pre>
  
  <p>I have no problems with:</p>
  
  <pre><code> var myset = new Set([1,5,3,2,7,9]);
   myset.geq(3,4)
   false
  </code></pre>
  
  <p>but still:</p>
  
  <pre><code> myset.arr.sort(myset.geq)
  
   TypeError: Object #&lt;Object&gt; has no method 'leq'
   at ...
  </code></pre>
  
  <p>So: How do I create a method (like <code>geq</code>) in my object that has access to another method (like <code>leq</code>) in the same object when I need to access the first method to e.g. the <code>sort</code> function?</p>