I am trying to learn the best practices of creating objects and object instances. One way I understood of doing this was by using a closure to return an object all wrapped up as an IIF:
myApp2 = (function() {
var count = 1;
return {
getCount: function(){return count},
incCount: function(){count++}
};
}())
var test = myApp2
console.log(test.getCount()); // outputs 1
console.log(test.incCount()); // increment count by 1
console.log(test.getCount()); // outputs 2
var test2 = myApp2 // I thought this would create new context
console.log(test2.getCount());// outputs 2, not 1 as expected
Please correct my understanding..