fix Ox.clone(0, deep)
This commit is contained in:
parent
d41e12de2f
commit
19afdd8bea
1 changed files with 4 additions and 4 deletions
|
@ -30,7 +30,9 @@ Ox.clone <f> Returns a (shallow or deep) copy of an array or object
|
||||||
@*/
|
@*/
|
||||||
Ox.clone = function(collection, deep) {
|
Ox.clone = function(collection, deep) {
|
||||||
var ret, type = Ox.typeOf(collection);
|
var ret, type = Ox.typeOf(collection);
|
||||||
if (deep) {
|
if (type != 'array' && type != 'object') {
|
||||||
|
ret = collection;
|
||||||
|
} else if (deep) {
|
||||||
ret = type == 'array' ? [] : {};
|
ret = type == 'array' ? [] : {};
|
||||||
Ox.forEach(collection, function(value, key) {
|
Ox.forEach(collection, function(value, key) {
|
||||||
type = Ox.typeOf(value);
|
type = Ox.typeOf(value);
|
||||||
|
@ -38,9 +40,7 @@ Ox.clone = function(collection, deep) {
|
||||||
? Ox.clone(value, true) : value;
|
? Ox.clone(value, true) : value;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
ret = type == 'array' ? collection.slice()
|
ret = type == 'array' ? collection.slice() : Ox.extend({}, collection)
|
||||||
: type == 'object' ? Ox.extend({}, collection)
|
|
||||||
: collection;
|
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue