Adding clone functionality to Contact object

This commit is contained in:
macdonst
2010-09-30 23:51:07 +08:00
parent a772acbd89
commit 297ddb99fe
3 changed files with 107 additions and 22 deletions
+36
View File
@@ -324,6 +324,42 @@ PhoneGap.stringify = function(args) {
}
};
/**
* Does a deep clone of the object.
*
* @param obj
* @return
*/
PhoneGap.clone = function(obj) {
if(!obj) {
return obj;
}
if(obj instanceof Array){
var retVal = new Array();
for(var i = 0; i < obj.length; ++i){
retVal.push(PhoneGap.clone(obj[i]));
}
return retVal;
}
if (obj instanceof Function) {
return obj;
}
if(!(obj instanceof Object)){
return obj;
}
retVal = new Object();
for(i in obj){
if(!(i in retVal) || retVal[i] != obj[i]) {
retVal[i] = PhoneGap.clone(obj[i]);
}
}
return retVal;
};
PhoneGap.callbackId = 0;
PhoneGap.callbacks = {};