Merge pull request #180 from aeosynth/instanceof

instanceof Array
This commit is contained in:
Mayhem 2012-02-05 04:58:51 -08:00
commit 6742f09a4f
2 changed files with 12 additions and 16 deletions

View File

@ -186,17 +186,15 @@
(flatten = function(parent, obj) {
var key, val, _results;
if (typeof obj === 'object') {
if (obj.length) {
return conf[parent] = obj[0];
} else {
_results = [];
for (key in obj) {
val = obj[key];
_results.push(flatten(key, val));
}
return _results;
if (obj instanceof Array) {
return conf[parent] = obj[0];
} else if (typeof obj === 'object') {
_results = [];
for (key in obj) {
val = obj[key];
_results.push(flatten(key, val));
}
return _results;
} else {
return conf[parent] = obj;
}

View File

@ -112,12 +112,10 @@ log = console.log.bind? console
# flatten the config
conf = {}
(flatten = (parent, obj) ->
if typeof obj is 'object'
# array
if obj.length
conf[parent] = obj[0]
# object
else for key, val of obj
if obj instanceof Array
conf[parent] = obj[0]
else if typeof obj is 'object'
for key, val of obj
flatten key, val
else # string or number
conf[parent] = obj