Skip to content

Commit

Permalink
fix: Ensure Function.isFunction recognizes async functions
Browse files Browse the repository at this point in the history
  • Loading branch information
medikoo committed Aug 30, 2019
1 parent dd6fc3f commit 6f06e66
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions function/is-function.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"use strict";

var objToString = Object.prototype.toString
, id = objToString.call(require("./noop"));
, isFunctionStringTag = RegExp.prototype.test.bind(/^[object [A-Za-z0-9]*Function]$/);

module.exports = function (value) {
return typeof value === "function" && objToString.call(value) === id;
return typeof value === "function" && isFunctionStringTag(objToString.call(value));
};
6 changes: 6 additions & 0 deletions test/function/is-function.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,10 @@ var o = { call: Function.prototype.call, apply: Function.prototype.apply };
module.exports = function (t, a) {
a(t(function () {}), true, "Function is function");
a(t(o), false, "Plain object is not function");
var asyncFunction;
try { asyncFunction = eval("async () => {}"); }
catch (error) {}
if (asyncFunction) {
a(t(asyncFunction), true, "Async function is function");
}
};

0 comments on commit 6f06e66

Please sign in to comment.