clone.js 472 B

1234567891011121314151617181920212223
  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. };