Class Emulation - Module Pattern vs. Function Objects
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/3790909/javascript-module-pattern-vs-constructor-prototype-pattern">Javascript: Module Pattern vs Constructor/Prototype pattern?</a>  </p>
</blockquote>



<p>I want to use class emulation in javaScript.  This is a preference.</p>

<p>I've been using the module pattern but am considering using just a simple function object as I can create public and private member variables and functions.</p>

<p><a href="http://jsfiddle.net/chrisallenaaker/Dqg28/" rel="nofollow">Here</a> is an example of a function-object emulating a class:</p>

<pre><code>var input = document.getElementById('input');
var output = document.getElementById('output');

function test()
{
    var private_var = 'private_var';
    var private_func = function(){ return 'private_func';};
    var my = {};
    my.public_var = 'public_var';
    my.public_func = function(){ return 'public_func';};
    return my;
}

var object_test = new test();

alert( '| ' + object_test.public_var);
alert( '| ' + object_test.private_var);

alert( '| ' + object_test.public_func() );
alert( '| ' + object_test.private_func() );

​
</code></pre>

<p><a href="http://www.adequatelygood.com/2010/3/JavaScript-Module-Pattern-In-Depth" rel="nofollow">Here</a> is an example of a the module pattern emulating a class.</p>

<p>What are the primary differences? Besides the ability to make implied global explicit, are there any?</p>
