Possible Duplicate:
Javascript: Module Pattern vs Constructor/Prototype pattern?
I want to use class emulation in javaScript. This is a preference.
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.
Here is an example of a function-object emulating a class:
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() );
Here is an example of a the module pattern emulating a class.
What are the primary differences? Besides the ability to make implied global explicit, are there any?