From d407d8aa08a6f739441a82e3b7c9d8a5cf66ba16 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Thu, 1 Oct 2015 08:55:49 -0700 Subject: [PATCH] Ensure `_.isFunction` returns `true` for generator functions. [closes #1498] --- lodash.js | 7 ++++++- test/test.js | 10 ++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lodash.js b/lodash.js index 9cab06d21..3abd8b463 100644 --- a/lodash.js +++ b/lodash.js @@ -68,6 +68,7 @@ dateTag = '[object Date]', errorTag = '[object Error]', funcTag = '[object Function]', + genTag = '[object GeneratorFunction]', mapTag = '[object Map]', numberTag = '[object Number]', objectTag = '[object Object]', @@ -8697,7 +8698,11 @@ // The use of `Object#toString` avoids issues with the `typeof` operator // in Safari 8 which returns 'object' for typed array constructors, and // PhantomJS 1.9 which returns 'function' for `NodeList` instances. - return isObject(value) && objToString.call(value) == funcTag; + if (!isObject(value)) { + return false; + } + var tag = objToString.call(value); + return tag == funcTag || tag == genTag; } /** diff --git a/test/test.js b/test/test.js index 1a2bd4443..e41238554 100644 --- a/test/test.js +++ b/test/test.js @@ -8549,6 +8549,16 @@ assert.strictEqual(_.isFunction(slice), true); }); + QUnit.test('should return `true` for generator functions', function(assert) { + assert.expect(1); + + var generator = _.attempt(function() { + return Function('return function*(){}'); + }); + + assert.strictEqual(_.isFunction(generator), typeof generator == 'function'); + }); + QUnit.test('should return `true` for typed array constructors', function(assert) { assert.expect(1);