In JS often encounter the assignment of a variable to a new variable, which is easy to implement for the basic type, directly by the equal sign assignment is possible, for reference types can not be the Case. (note: like functions, Regular can also be assigned directly by the equal Sign)
Here I wrote a copy of the value of the function, can be deep copy, also can be shallow copy, for deep copy only need to set the second parameter to True
functionclone (data,deep) {varClonedata =undefined; vardata = Arguments[0],deep = Arguments[1]; if(!deep ) { returndata; }Else{ if(typeofDeep = = ' Boolean '){ if(className (data) = = = ' Object ') {clonedata= {}; for(keyinchData) { if(data.hasownproperty (key)) {clonedata[key]=Arguments.callee (data[key],deep); } } returnclonedata; }Else if(className (data) = = = ' Array ') {clonedata= []; for(vari = 0,len = data.length;i<len;i++) {clonedata[i]=Arguments.callee (data[i],deep); } returnclonedata; }Else{ returndata}}Else{ returndata; } }}functionclassName (obj) {returnObject.prototype.toString.call (obj). Slice (8,-1);}
JavaScript variable Assignment