Permalink
Browse files

Minor refactoring

  • Loading branch information...
simov committed Aug 22, 2017
1 parent 14b63bd commit bd00dcdf407889a6ced6ccce137db246adc5b93e
Showing with 18 additions and 11 deletions.
  1. +18 −11 index.js
View
@@ -26,31 +26,38 @@
if (target instanceof Date) {
return new Date(target.getTime())
}
var copy = (target instanceof Array) ? [] : {}
;(function read (target, copy) {
walk(target, copy)
return copy
function walk (target, copy) {
for (var key in target) {
var obj = target[key]
if (obj instanceof Array) {
var value = []
var last = add(copy, key, value)
read(obj, last)
}
else if (obj instanceof Date) {
if (obj instanceof Date) {
var value = new Date(obj.getTime())
add(copy, key, value)
}
else if (obj instanceof Object && typeof obj !== 'function') {
else if (obj instanceof Function) {
var value = obj
add(copy, key, value)
}
else if (obj instanceof Array) {
var value = []
var last = add(copy, key, value)
walk(obj, last)
}
else if (obj instanceof Object) {
var value = {}
var last = add(copy, key, value)
read(obj, last)
walk(obj, last)
}
else {
var value = obj
add(copy, key, value)
}
}
}(target, copy))
return copy
}
}
/**

0 comments on commit bd00dcd

Please sign in to comment.