title: Javascript Function `Recreation´?
body: <p>I read a lot of JavaScript code and see lots of different styles of making so-called Classes. I'm developing a light-weight DOMish class which contains the bare minimum for my template script, running on Node.JS, (which transforms a DOMish instance into another DOMish instance using JSON and then serializes it to HTML, caching the original DOMish instance and cloning it per template-request).</p>
  
  <p>Above is all irrelevant to my question. After reading <a href="http://www.phpied.com/3-ways-to-define-a-javascript-class/" rel="nofollow">http://www.phpied.com/3-ways-to-define-a-javascript-class/</a>, Section 1.2. Methods defined internally</p>
  
  <blockquote>
    <p>A drawback of 1.1. is that the method getInfo() is recreated every time you create a new object.</p>
  </blockquote>
  
  <p>The way of defining classes, as described in Section 1.1, is (slightly modified to reflect to my own case, using local/private variables):</p>
  
  <pre><code>function Apple (type) {
      var that = this;
  
      // local-variable
      var color = 'red';
  
      // local-(extern)-function
      var infoProvider = function() { // inner-function
          // note the danger of this and that!
          return that.color + ' ' + that.type + ' ' + this.type;
      };
  
      this.__defineGetter__("type", function() { return type; });
  
      this.getInfo = function(otherContext) {
          return infoProvider.call(otherContext); // other "this" scope
      };
  }
  
  var apple = new Apple('iPod');
  apple.getInfo({type: 'music player'}); // 'red iPod music player'
  </code></pre>
  
  <p>I happen to use the same style, as the function now has access to local/private variables and functions, defined inside the constructor. But the sentence "[The function] is recreated every time you create a new object." scares me (<em>performance</em> wise)! As I'm using Node, which uses V8, I always thought that functions are only created once and cached some-how, when called on different objects, using only a different context (the <code>this</code>es and the <code>that</code>s).</p>
  
  <p>Should I be scared of "recreation"? How bad is it compared to prototype-based functions? Or is this purely aesthetic (people love keeping stuff together, in the constructor, VS, people love prototypes)?</p>