function fadeObject(colour, time){ this.time = time; this.newMask = colour.red; this.oldMask = CreateColor(0, 0, 0, 0); this.flagged = true; this.destroy = false; this.fadeTime = time; this.fadeCount = 1; Abort(this.newMask) this.fadeColourDifference = {}; this.fadeColourDifference.red = (this.newMask.red - this.oldMask.red) / this.fadeTime; this.fadeColourDifference.blue = (this.newMask.blue - this.oldMask.blue) / this.fadeTime; this.fadeColourDifference.green = (this.newMask.green - this.oldMask.green) / this.fadeTime; this.fadeColourDifference.alpha = (this.newMask.alpha - this.oldMask.alpha) / this.fadeTime ;}
this.fadeColourDifference.red = (this.newMask.red - this.oldMask.red) / this.fadeTime;
function clone(o){ if (typeof o === 'object' && o !== null) { var dolly = {}; for (var p in o) { dolly[p] = clone(o[p]); } } else { dolly = o; } return dolly;}
/*** Serialize(obj : object);* - Use this to JSON an object; AND preserve the data type.**/function Serialize(obj){ function Make(obj) { var o = Assert.isArray(obj) ? [] : { zztype: obj.constructor.name }; for (var i in obj) { if (Assert.is(obj[i], "object")) o[i] = Make(obj[i]); else o[i] = obj[i]; } return o; } if(Assert.is(obj, "object")) return JSON.stringify(Make(obj)); else return JSON.stringify(obj);}/*** Deserialize(s : string);* - Use this to parse a JSON object; AND restore the methods.**/function Deserialize(s){ function Make(o) { var obj = []; if (!Assert.isArray(o)) { if (o.zztype in this) obj = new global[o.zztype](); else { Debug.log("Can't deserialize type: {?}", o.zztype, LIB_ERROR); return; } } for (var i in o) { if (Assert.is(o[i], "object")) obj[i] = Make(o[i]); else obj[i] = o[i]; } if (!Assert.isArray(obj)) delete obj.zztype; return obj; } return Make(JSON.parse(s));}/*** DeepClone(obj : object);* - generates a full, deep, and accurate copy of the object.**/function DeepClone(obj) { return Deserialize(Serialize(obj));}
DeepClone({a: 1, b: function () { return 2; }});
/*** ShallowClone(obj : object);* - generates a shallow copy of the object.**/function ShallowClone(obj) { var o = new global[obj.constructor.name](); Absorb(o, obj); return o;}
function clone(o){ var clones = arguments.length >= 2 ? arguments[1] : []; if (typeof o === 'object' && o !== null) { for (var i = 0; i < clones.length; ++i) { if (o === clones[i].original) { return clones[i].dolly; } } var dolly = {}; clones.push({ original: o, dolly: dolly }); for (var p in o) { dolly[p] = clone(o[p], clones); } return dolly; } else { return o; }};
but really, if you have a constructor-created object that you want to clone, that object should ideally implement its own clone method.