From 1aafb6c2c1756220e11ed922b56b88521a47370c Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sat, 20 Sep 2014 11:47:34 -0700 Subject: [PATCH] Use type checks when checking for a `prototype` property. --- lodash.js | 6 +++--- test/test.js | 6 +++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lodash.js b/lodash.js index ffc3f985e..c0e26360c 100644 --- a/lodash.js +++ b/lodash.js @@ -7627,7 +7627,7 @@ var Ctor = object.constructor, length = object.length; } - if ((Ctor && Ctor.prototype === object) || + if ((typeof Ctor == 'function' && Ctor.prototype === object) || (typeof length == 'number' && length > 0) || (support.enumPrototypes && typeof object == 'function')) { return shimKeys(object); @@ -7670,7 +7670,7 @@ var keyIndex, Ctor = object.constructor, index = -1, - isProto = Ctor && Ctor.prototype === object, + isProto = typeof Ctor == 'function' && Ctor.prototype === object, maxIndex = length - 1, result = Array(length), skipIndexes = length > 0, @@ -7947,7 +7947,7 @@ accumulator = []; } else if (isObject(object)) { var Ctor = object.constructor; - accumulator = baseCreate(Ctor && Ctor.prototype); + accumulator = baseCreate(typeof Ctor == 'function' && Ctor.prototype); } else { accumulator = {}; } diff --git a/test/test.js b/test/test.js index b4e0e32c5..34a1a46d4 100644 --- a/test/test.js +++ b/test/test.js @@ -6818,7 +6818,7 @@ deepEqual(func(Foo).sort(), expected); }); - test('`_.' + methodName + '` skips the `constructor` property on prototype objects', 2, function() { + test('`_.' + methodName + '` skips the `constructor` property on prototype objects', 3, function() { function Foo() {} Foo.prototype.a = 1; @@ -6827,6 +6827,10 @@ Foo.prototype = { 'constructor': Foo, 'a': 1 }; deepEqual(func(Foo.prototype), ['a']); + + var Fake = { 'prototype': {} }; + Fake.prototype.constructor = Fake; + deepEqual(func(Fake.prototype), ['constructor']); }); test('`_.' + methodName + '` should ' + (isKeys ? 'not' : '') + ' include inherited properties', 1, function() {