The equal sign assignment operation of objects in Javascript is a reference method. If you want to use the copy assignment operation, you need to implement functions like clone in Java. The implementation method is to copy the object content one by one. The implementation is as follows:
Method 1:
function clone(myObj){ if(typeof(myObj) != 'object') return myObj; if(myObj == null) return myObj; var myNewObj = new Object(); for(var i in myObj) myNewObj[i] = clone(myObj[i]); return myNewObj; }
Method 2:Implementation through object prototype Extension
Object.prototype.Clone = function() { var objClone; if ( this.constructor == Object ) objClone = new this.constructor(); else objClone = new this.constructor(this.valueOf()); for ( var key in this ) { if ( objClone[key] != this[key] ) { if ( typeof(this[key]) == 'object' ) { objClone[key] = this[key].Clone(); } else { objClone[key] = this[key]; } } } objClone.toString = this.toString; objClone.valueOf = this.valueOf; return objClone; }