diff --git a/lodash.js b/lodash.js index 47f0db1aa..e74259907 100644 --- a/lodash.js +++ b/lodash.js @@ -6945,9 +6945,10 @@ if (isArr) { accumulator = []; } else { - var ctor = object && object.constructor, - proto = ctor && ctor.prototype; - + if (isObject(object)) { + var ctor = object.constructor, + proto = ctor && ctor.prototype; + } accumulator = baseCreate(proto); } } diff --git a/test/test.js b/test/test.js index d77c215ae..7829a64de 100644 --- a/test/test.js +++ b/test/test.js @@ -9404,6 +9404,10 @@ ok(_.transform(new Foo) instanceof Foo); }); + test('should check that `object` is an object before using it as the `accumulator` `[[Prototype]]', 1, function() { + ok(!(_.transform(1) instanceof Number)); + }); + _.each({ 'array': [1, 2, 3], 'object': { 'a': 1, 'b': 2, 'c': 3 }