var cloneObject = (function(global) {
function ObjMap() {
this._data = [];
}
ObjMap.prototype = {
constructor: ObjMap,
_get: function(key) {
for (var i = 0; i < this._data.length; ++i) {
if (this._data[i].key === key) {
return this._data[i];
}
}
return null;
},
get: function(key) {
var data = this._get(key);
return data ? data.value : void(0);
},
set: function(key, value) {
var data = this._get(key);
if (data) {
data.value = value;
} else {
this._data.push({ key: key, value: value });
}
}
};
function cloneObject(obj, map) {
var clone = map.get(obj);
if (clone) {
return clone;
}
clone = {};
map.set(obj, clone);
for (var i in obj) {
if (obj.hasOwnProperty(i)) {
if (obj[i] && typeof obj[i] == "object") {
clone[i] = cloneObject(obj[i], map);
} else {
clone[i] = obj[i];
}
}
}
return clone;
}
return function(obj) {
var map = global.Map ? new Map() : new ObjMap();
return cloneObject(obj, map);
};
})(window);