Kevin 29b9a0c50c clean && clean html base | 4 年之前 | |
---|---|---|
.. | ||
bower_components | 4 年之前 | |
.npmignore | 4 年之前 | |
HISTORY.md | 4 年之前 | |
LICENSE | 4 年之前 | |
README.md | 4 年之前 | |
bower.json | 4 年之前 | |
deepcopy.js | 4 年之前 | |
package.json | 4 年之前 | |
testem.json | 4 年之前 |
deep copy for any data
$ npm install deepcopy
$ bower install deepcopy
var deepcopy = require('deepcopy');
<script src="deepcopy.min.js"></script>
define deepcopy
by define()
if using AMD loader.
otherwise deepcopy
export to global.
var data, shallow, deep;
data = {
objects: {
array: [
null, undefined, new Date, /deepcopy/ig
],
object: {
number: NaN,
string: 'A',
boolean: true
},
to: null
}
};
// circular reference
data.objects.to = data;
// shallow copy and deep copy
shallow = data;
deep = deepcopy(data);
// remove entry
delete data.objects;
// results
console.log(data);
// {}
console.log(shallow);
// {}
console.log(require('util').inspect(deep, { depth: null }));
// { objects:
// { array:
// [ null,
// undefined,
// Sat Jan 10 2015 03:18:32 GMT+0900 (JST),
// /deepcopy/gi ],
// object: { number: NaN, string: 'A', boolean: true },
// to: [Circular] } }
var data, deep;
data = { object: {} };
data.object[Symbol.for('sym')] = 123;
deep = deepcopy(data);
delete data.object;
console.log(data.object);
// undefined
console.log(deep.object[Symbol.for('sym')]);
// 123
value
*
- copy target valuereturn
*
- deep copied valuereturn deep copied value.
supported types are below:
$ npm install
$ npm test
$ npm install
$ npm run bower
$ npm run testem
The MIT license. Please see LICENSE file.