-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
28 lines (23 loc) · 824 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
let toStrFn = Object.prototype.toString;
/**
* here define an async function
* it will throw a SyntaxError while your javascript runtime is not support AsyncFunction featrue
*/
let asyncFunction = async function () { };
let prototypeOfAsyncFunction = Object.getPrototypeOf(asyncFunction);
/**
* normally, it will return 'AsyncFunction'
*/
let asyncFunctionName = asyncFunction.constructor.name;
/**
* normally, it will return '[object AsyncFunction]'
*/
let protoStr = toStrFn.call(asyncFunction);
let isAsyncFunction = function (obj) {
if (typeof obj !== 'function') return false;
return obj.constructor
&& obj.constructor.name === asyncFunctionName
&& toStrFn.call(obj) === protoStr
&& Object.getPrototypeOf(obj) === prototypeOfAsyncFunction;
}
module.exports = isAsyncFunction;