clone.js 472 B

123456789101112131415161718192021222324
  1. 'use strict';
  2. var List = require('./list');
  3. module.exports = function clone(node) {
  4. var result = {};
  5. for (var key in node) {
  6. var value = node[key];
  7. if (value) {
  8. if (Array.isArray(value) || value instanceof List) {
  9. value = value.map(clone);
  10. } else if (value.constructor === Object) {
  11. value = clone(value);
  12. }
  13. }
  14. result[key] = value;
  15. }
  16. return result;
  17. };