mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 18:37:50 +00:00
Ensure _.isFunction returns true for generator functions. [closes #1498]
This commit is contained in:
@@ -68,6 +68,7 @@
|
|||||||
dateTag = '[object Date]',
|
dateTag = '[object Date]',
|
||||||
errorTag = '[object Error]',
|
errorTag = '[object Error]',
|
||||||
funcTag = '[object Function]',
|
funcTag = '[object Function]',
|
||||||
|
genTag = '[object GeneratorFunction]',
|
||||||
mapTag = '[object Map]',
|
mapTag = '[object Map]',
|
||||||
numberTag = '[object Number]',
|
numberTag = '[object Number]',
|
||||||
objectTag = '[object Object]',
|
objectTag = '[object Object]',
|
||||||
@@ -8697,7 +8698,11 @@
|
|||||||
// The use of `Object#toString` avoids issues with the `typeof` operator
|
// The use of `Object#toString` avoids issues with the `typeof` operator
|
||||||
// in Safari 8 which returns 'object' for typed array constructors, and
|
// in Safari 8 which returns 'object' for typed array constructors, and
|
||||||
// PhantomJS 1.9 which returns 'function' for `NodeList` instances.
|
// 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
10
test/test.js
10
test/test.js
@@ -8549,6 +8549,16 @@
|
|||||||
assert.strictEqual(_.isFunction(slice), true);
|
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) {
|
QUnit.test('should return `true` for typed array constructors', function(assert) {
|
||||||
assert.expect(1);
|
assert.expect(1);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user