Skip to content

Commit b20afdd

Browse files
committed
Fix IE non-enumerable properties
I’m not sure what we were doing before with the `FuncProto`…
1 parent cd725e1 commit b20afdd

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

test/objects.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
A.prototype.foo = 'foo';
6767
var b = new A();
6868
b.bar = 'bar';
69-
deepEqual(_.allKeys(b), ['bar', 'foo'], 'should include inherited keys');
69+
deepEqual(_.allKeys(b), ['foo', 'bar'], 'should include inherited keys');
7070

7171
function y() {}
7272
y.x = 'z';

underscore.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -896,17 +896,21 @@
896896

897897
// Keys in IE < 9 that won't be iterated by `for key in ...` and thus missed.
898898
var hasEnumBug = !{toString: null}.propertyIsEnumerable('toString');
899-
var nonEnumerableProps = ['constructor', 'valueOf', 'isPrototypeOf', 'toString',
899+
var nonEnumerableProps = ['valueOf', 'isPrototypeOf', 'toString',
900900
'propertyIsEnumerable', 'hasOwnProperty', 'toLocaleString'];
901901

902902
function collectNonEnumProps(obj, keys) {
903903
var nonEnumIdx = nonEnumerableProps.length;
904-
var proto = typeof obj.constructor === 'function' ? FuncProto : ObjProto;
904+
var constructor = obj.constructor;
905+
var proto = (_.isFunction(constructor) && constructor.prototype) || ObjProto;
906+
907+
// Constructor is a special case.
908+
var prop = 'constructor';
909+
if (_.has(obj, prop) && !_.contains(keys, prop)) keys.push(prop);
905910

906911
while (nonEnumIdx--) {
907-
var prop = nonEnumerableProps[nonEnumIdx];
908-
if (prop === 'constructor' ? _.has(obj, prop) : prop in obj &&
909-
obj[prop] !== proto[prop] && !_.contains(keys, prop)) {
912+
prop = nonEnumerableProps[nonEnumIdx];
913+
if (prop in obj && obj[prop] !== proto[prop] && !_.contains(keys, prop)) {
910914
keys.push(prop);
911915
}
912916
}

0 commit comments

Comments
 (0)