title: Rules to Replace 'New'
body: <p>In his "Good Parts," Crockford suggests that 'new' should never be used.  To follow that rule, how would you refactor the following code? </p>
  
  <pre><code>function Range(from, to) { 
      this.from = from; 
      this.to = to; 
  } 
  
  Range.prototype = { 
      includes: function(x) {
          return this.from &lt;= x &amp;&amp; x &lt;= this.to;
      }, 
  
      foreach: function(f) { 
          for(var x = Math.ceil(this.from); x &lt;= this.to; x++) f(x);
      },
  
      toString: function() { 
          return "(" + this.from + "..." + this.to + ")"; 
      } 
  };
  
  // Here are example uses of a range object 
  var r = new Range(1,3); // Create a range object 
  r.includes(2); // =&gt; true: 2 is in the range 
  r.foreach(console.log); // Prints 1 2 3
  </code></pre>
  
  <p>I spotted his <a href="http://yuiblog.com/blog/2006/11/13/javascript-we-hardly-new-ya/" rel="nofollow">additional advice</a>, but it wasn't clear how to apply it in this (presumably very common) case.  Would he propose to create a factory function that contains a giant object literal?  If yes, isn't that inefficient? ISTM that such a factory function, upon each invocation, creates duplicate functions.  In other words, there is no one prototype holding shared custom methods. </p>
  
  <p>It seems something is left unsaid in his advice, I'm hoping someone can clear it up.</p>