make Ox.clone() return a deep (not shallow) copy
This commit is contained in:
parent
9dd695b6ca
commit
a8b9e1fd2c
1 changed files with 9 additions and 3 deletions
12
source/Ox.js
12
source/Ox.js
|
@ -289,15 +289,21 @@ Ox.avg = function(obj) {
|
|||
};
|
||||
|
||||
/*@
|
||||
Ox.clone <f> Returns a (shallow) copy of an object or array
|
||||
Ox.clone <f> Returns a (deep) copy of an object or array
|
||||
> (function() { a = ['val']; b = Ox.clone(a); a[0] = null; return b[0]; }())
|
||||
'val'
|
||||
> (function() { a = {key: 'val'}; b = Ox.clone(a); a.key = null; return b.key; }())
|
||||
'val'
|
||||
@*/
|
||||
|
||||
Ox.clone = function(obj) {
|
||||
return Ox.isArray(obj) ? obj.slice() : Ox.extend({}, obj);
|
||||
Ox.clone = function(col) {
|
||||
// return Ox.isArray(col) ? col.slice() : Ox.extend({}, col);
|
||||
var clone = Ox.isArray(col) ? [] : {};
|
||||
Ox.forEach(col, function(val, key) {
|
||||
clone[key] = ['array', 'object'].indexOf(Ox.typeOf(val)) > -1
|
||||
? Ox.clone(val) : val;
|
||||
});
|
||||
return clone;
|
||||
};
|
||||
|
||||
/*@
|
||||
|
|
Loading…
Reference in a new issue