Und das ganze noch ohne Fehler :-/
var Expando = (function () {
var container = {};
var uuid_t = "Expando_";
var uuid_i = 0;
function uuid () {
return uuid_t+(uuid_i++);
}
return {
getDataForElem : function (elem) {
return container[elem.id];
},
setDataForElem : function (elem, data) {
var id;
if (elem.id && elem.id !== '') {
id = elem.id;
} else {
do {
id = uuid();
} while (document.getElementById(id));
elem.id = id;
}
if (!container[id]) {
container[id] = data;
} else {
for (var key in data) {
if (data.hasOwnProperty(key)) {
container[id][key] = data[key];
}
}
}
}
};
})();