@leyyo/common 1.3.15 → 1.3.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/function/is-class.js +18 -7
- package/package.json +1 -1
|
@@ -5,14 +5,25 @@
|
|
|
5
5
|
* @return {boolean} - is class?
|
|
6
6
|
* */
|
|
7
7
|
export function isClass(fn) {
|
|
8
|
-
|
|
9
|
-
if (!(fn && fn.constructor === Function) || fn.prototype === undefined) {
|
|
8
|
+
if (typeof fn !== 'function') {
|
|
10
9
|
return false;
|
|
11
10
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return true;
|
|
11
|
+
try {
|
|
12
|
+
return Function.prototype.toString.call(fn).toString().startsWith('class ');
|
|
15
13
|
}
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
catch (e) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
// // Class constructor is also a function
|
|
18
|
+
// if ( !(fn && fn.constructor === Function) || (fn as Fnc).prototype === undefined) {
|
|
19
|
+
// return false;
|
|
20
|
+
// }
|
|
21
|
+
//
|
|
22
|
+
// // This is a class that extends other class
|
|
23
|
+
// if (Function.prototype !== Object.getPrototypeOf(fn)) {
|
|
24
|
+
// return true;
|
|
25
|
+
// }
|
|
26
|
+
//
|
|
27
|
+
// // Usually a function will only have 'constructor' in the prototype
|
|
28
|
+
// return Object.getOwnPropertyNames((fn as Fnc).prototype).length > 1;
|
|
18
29
|
}
|