Fundamental JavaScript OO
<p>Ok I <strong>should</strong> know the answer to this but for some reason I have never really understood or had the need to really get to know JavaScript. </p>

<blockquote>
  <p>My question is: Looking at the code samples below am I correct in my understanding or am I missing some information. </p>
</blockquote>

<hr>

<p><strong>Sample 1</strong></p>

<p>Need to instantiate the function (or class) in order to use the <code>IsOld</code> method, and a separate copy of the <code>IsOld</code> function will be created for each instance.</p>

<pre><code>function MyClass1() {
    this.IsOld = function (age) {
        if (age &gt; 40) {
            return true;
        }
        return false;
    };
}

// sample usage
var m1 = new MyClass1();
console.log(m1.IsOld(34));
</code></pre>

<hr>

<p><strong>Sample 2</strong></p>

<p>Need to instantiate but unlike <code>MyClass1</code> the scripting engine will not need to create a copy of the method <code>IsOld</code> for each class instance.</p>

<pre><code>var MyClass2 = (function () {
    function MyClass2() { }

    MyClass2.prototype.IsOld = function (age) {
        if (age &gt; 40) {
            return true;
        }
        return false;
    };

    return MyClass2;
})();

// sample usage
var m2 = new MyClass2();
console.log(m2.IsOld(34));
</code></pre>

<hr>

<p><strong>Sample 3</strong></p>

<p>No need to instantiate the function / class to access the <code>IsOld</code> method. A single instance of the <code>IsOld</code> method is used across all invocations. </p>

<pre><code>var MyClass3 = {
    IsOld: function (age) {
        if (age &gt; 40) {
            return true;
        }
        return false;
    },
};

// sample uage
console.log(MyClass3.IsOld(34));
</code></pre>

<p>Note: I am guessing there are plenty of similar question / answers here on SO but for some reason I could not find one that actually made sense to me. </p>
