Why not just add a reference to the parent in the item class.
var parentObj = {
items : [],
addItem : function () {
var newItem = new ItemObj;
newItem.parent = this; // set the parent here
items.push(newItem);
},
removeItem : function (item) {
for (var i = this.items.length; i--; i < 0) {
if (this.items[i] == item) {
this.items.splice(i, 1);
return;
}
}
}
};
function ItemObj() {}
ItemObj.prototype = {
parent: null,
observers : [],
observerRemove : function(observer){
//find observer in observers array and splice it out
....
//now here's the part where it gets tricky
if (this.observers.length == 0) {
this.parent.removeItem(this); // use the parent here
}
},
//observerAdd.... etc
};