Detailed Value copy functions for JS data types (deep copy)

Not more nonsense, directly passed the code, the specific code is as follows:

  Function Mottoclone (obj) {if (Obj === NULL || TypeOf Obj! == 'Object') Return Obj; if (Obj InstanceOf Boolean) Return New Boolean (Obj InstanceOf Number) Return New Number (Obj.Valueof (); IF Obj InstanceOf String) Return New String (Obj InstanceOf Regexp) Return New Regexp (Obj InstanceOf Date) Return New Date (Obj.Valueof ()); var Cpobj = obj instanceof array? []: {}; for (var key in obj) cpobj [key] = myclone (obj [key]); return cpobj;}  

Supported data types or formats are: Boolean, Number, String, Regexp, Date, Function, Array, JSON

Supports deep copy (cyclic iteration), such as:

 VAR OBJ = {ID: 1, Name: 'XXX', SAYNAME: Function () {Console.log ('My Name IS'+;}, childs: [{}, {}, ...], opts: {xxx: [], ...}, ...}; var newobj = mottoclone (obj);   
The above is the value copy function of the JS data type described by Xiaobia, I hope that everyone can help, if you have any questions, please give me Message, the small package will reply to everyone in time. Thank you very much for your support of Tumi Cloud Website!

© Copyright Notice
Just support it if you like
comment Grab the couch

Please log in to comment