From aa40ca01df9ed030fa73ad607a617bed7d712373 Mon Sep 17 00:00:00 2001 From: James Campos Date: Sun, 5 Feb 2012 02:13:05 -0800 Subject: [PATCH] instanceof Array --- 4chan_x.user.js | 18 ++++++++---------- script.coffee | 10 ++++------ 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 58309cfd8..bf21e352c 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -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; } diff --git a/script.coffee b/script.coffee index 8994a342f..7a6318d5f 100644 --- a/script.coffee +++ b/script.coffee @@ -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