lodash: Simplify _.keys fallback. [jddalton]

Former-commit-id: 15d265f4f16ab2418bb5dcddf68a2fd43ebdf5b2
This commit is contained in:
John-David Dalton
2012-04-26 15:46:47 -04:00
parent 947fc9ce97
commit adcc2dd8d2
3 changed files with 109 additions and 112 deletions

View File

@@ -266,7 +266,6 @@
}
var args = options.args,
exits = options.exits,
firstArg = /^[^,]+/.exec(args)[0],
init = options.init,
iterate = options.iterate,
@@ -286,8 +285,7 @@
('var index, result' + (init ? '=' + init : '')) + ';\n' +
// exit early if first argument, e.g. `collection`, is nullish or custom expression
'if (' + (options.exitsExp || firstArg + ' == undefined') + ')\n' +
// IE < 9 JScript will throw a syntax error if it encounters `return throw ...`
(/^throw\b/.test(exits) ? '' : 'return ') + (exits || 'result') + ';\n' +
'return ' + (options.exits || 'result') + ';\n' +
// add code after the exits if-statement but before the array/object iteration branches
(options.top || '') + ';\n' +
// the following branch is for iterating arrays and array-like objects
@@ -2209,8 +2207,7 @@
*/
var keys = nativeKeys || iterationFactory({
'args': 'object',
'exitsExp': 'object !== Object(object)',
'exits': 'throw TypeError()',
'exitsExp': '"key" in object, false',
'init': '[]',
'inLoop': 'result.push(index)'
});