misc fixes

This commit is contained in:
rlx 2011-09-20 00:11:16 +00:00
commit b881f74c7e
3 changed files with 18 additions and 9 deletions

View file

@ -434,12 +434,12 @@ Ox.clone <f> Returns a (shallow or deep) copy of an object or array
@*/
Ox.clone = function(col, deep) {
var ret;
// fixme: is there any use case for shallow copy?
var ret = Ox.isArray(col) ? [] : {};
if (deep) {
ret = Ox.isArray(col) ? [] : {};
Ox.forEach(col, function(val, key) {
ret[key] = ['array', 'object'].indexOf(Ox.typeOf(val)) > -1
? Ox.clone(val) : val;
? Ox.clone(val, true) : val;
});
} else {
ret = Ox.isArray(col) ? col.slice() : Ox.extend({}, col);
@ -700,6 +700,7 @@ Ox.isEmpty <f> Returns true if a collection is empty
true
@*/
Ox.isEmpty = function(val) {
// fixme: what about deep isEmpty?
return Ox.len(val) == 0;
};
@ -4233,11 +4234,15 @@ Ox.serialize <f> Parses an object into query parameters
'a=1&b=2&c=3'
> Ox.serialize({a: 1, b: 2.3, c: [4, 5]})
'a=1&b=2.3&c=4,5'
> Ox.serialize({string: 'foo', empty: {}, null: null, undefined: void 0})
'string=bar'
@*/
Ox.serialize = function(obj) {
var arr = [];
Ox.forEach(obj, function(val, key) {
arr.push(key + '=' + val);
if (!Ox.isEmpty(val) && !Ox.isNull(val) && !Ox.isUndefined(val)) {
arr.push(key + '=' + val);
}
});
return arr.join('&');
};