Issue #149: _.keys should throw a TypeError for non-objects.

This commit is contained in:
Kit Goncharov
2011-03-20 10:08:32 -06:00
parent 4869b4c6ca
commit 48abcd84c5
2 changed files with 26 additions and 0 deletions

View File

@@ -504,6 +504,7 @@
// Retrieve the names of an object's properties.
// Delegates to **ECMAScript 5**'s native `Object.keys`
_.keys = nativeKeys || function(obj) {
if (obj !== Object(obj)) throw new TypeError('Invalid object');
var keys = [];
for (var key in obj) if (hasOwnProperty.call(obj, key)) keys[keys.length] = key;
return keys;