javascript: private members and read-only properties
SCENARIO I have got this class: var AssocArray = function(){ var collection = new Object(); this.add = function(id, o){ collection[id] = o; } this.remove = function(id){ delete collection[id]; } this.getById = function(id){ return collection[id]; } this.get = function(){ var res = collection; return res; } } var myAssoc = new AssocArray(); myAssoc.add("11",{ "packageId": "11", "machineId": "1", "operationType": "Download"}); myAssoc.add("12",{ "packageId": "12", "machineId": "1", "operationType": "Download"}); myAssoc.add("14",{ "packageId": "14", "machineId": "1", "operationType": "Download"