I have the following class hierarchy:
- Storage
- Collection
- EixoCollection
- OfertaCollection
- Collection
And I have the following code:
var ofertaCollection = new OfertaCollection();
var eixoCollection = new EixoCollection();
ofertaCollection.set('mykey', 'myvalue');
alert(eixoCollection.get('mykey')); // it returns 'myvalue', should return nothing
The problem is that ofertaCollection and eixoCollection have properties referencing each other.
Follow the classes:
/**
* Storage
*
* @returns {Storage}
*/
function Storage(){
this.storage = []; // itens that have a key
// sets key
this.set = function(key, value){
this.storage[key] = value;
}
// gets key
this.get = function(key){
return this.storage[key];
}
}
/**
* Collection
*
* @returns {Collection}
*/
function Collection(){
}
Collection.prototype = new Storage();
/**
* EixoCollection
*
* @returns {EixoCollection}
*/
function EixoCollection(){
}
EixoCollection.prototype = new Collection();
/**
* OfertaCollection
*
* @returns {OfertaCollection}
*/
function OfertaCollection(){
}
OfertaCollection.prototype = new Collection();
What is the problem?
Collectionclass at all? Looks like serious bloat to me... all you've done is wrapped theStorageclass.