clone.js 465 B

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