Skip to content

Commit f916c5e

Browse files
committed
keys shim: use enumBug flag
1 parent f481883 commit f916c5e

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

underscore.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,7 @@
857857
// ----------------
858858

859859
// keys that won't be iterated by `for key in ...` and thus missed
860+
var hasEnumBug = !({toString: null}).propertyIsEnumerable('toString');
860861
var nonEnumerableProps = ['constructor', 'valueOf', 'isPrototypeOf', 'toString',
861862
'propertyIsEnumerable', 'hasOwnProperty', 'toLocaleString'];
862863

@@ -867,9 +868,11 @@
867868
if (nativeKeys) return nativeKeys(obj);
868869
var keys = [], nonEnumIdx = 7;
869870
for (var key in obj) if (_.has(obj, key)) keys.push(key);
870-
while (nonEnumIdx--) {
871-
var prop = nonEnumerableProps[nonEnumIdx];
872-
if (_.has(obj, prop) && !_.contains(keys, prop)) keys.push(prop);
871+
if (hasEnumBug) {
872+
while (nonEnumIdx--) {
873+
var prop = nonEnumerableProps[nonEnumIdx];
874+
if (_.has(obj, prop) && !_.contains(keys, prop)) keys.push(prop);
875+
}
873876
}
874877
return keys;
875878
};

0 commit comments

Comments
 (0)