I wonder about what the best way is to create an JavaScript object that has properties and methods.
I have seen examples where the person used var self = this<
var self = this<
You can also do it this way, using structures :
function createCounter () { var count = 0; return { increaseBy: function(nb) { count += nb; }, reset: function { count = 0; } } }
Then :
var counter1 = createCounter(); counter1.increaseBy(4);