isClassConstructor
Available since v0.7
The isClassConstructor()
is able to determine if a value is a class constructor.
Caution
isClassConstructor()
will only be able to return true
for classes that are defined using the class
keyword. See ES6 classes for additional information.
Built-in Classes
This util is NOT able to detect built-in classes. Use isConstructor()
if you wish to test for "constructable" functions / classes, including built-in classes.
import { isClassConstructor } from "@aedart/support/reflections";
isClassConstructor(null); // false
isClassConstructor({}); // false
isClassConstructor([]); // false
isClassConstructor(function() {}); // false
isClassConstructor(() => {}); // false
isClassConstructor(Array); // false
class A {}
isClassConstructor(A); // true
isClassConstructor(class {}); // true
Acknowledgement
The source code of the above shown methods is heavily inspired by Denis Pushkarev's Core-js implementation of the Function.isCallable / Function.isConstructor proposal (License MIT).
See also isConstructor()
.