var jabox = new function Jabox() { var _units = {}; var _products = {}; /** * Returns UnitEntity object with given id. * If object does not exist, it returns null; */ this.getUnit = function(id) { if(id == null) { return null; } var data = _units[id.toString()]; if(data == null) { this.onNonExistingEntity(); } return data; }; /** * Adds unit to collection. * * @param {UnitEntity} UnitEntity which has to be added to collection. */ this.addUnit = function(data) { _units[data.getId().toString()] = data; }; /** * Returns Product object with given id. * If object does not exist, it returns null; */ this.getProduct = function(id) { if(id == null) { return null; } var data = _products[id.toString()]; if(data == null) { this.onNonExistingEntity(); } return data; }; /** * Adds product to collection. * * @param {Product} Product which has to be added to collection. */ this.addProduct = function(data) { _products[data.getId().toString()] = data; }; this.onNonExistingEntity = function() { alert('Ooops, entity does not exist.'); }; };