isConstructor
Based on the TC39 Function.isCallable() / Function.isConstructor()
proposal, the isConstructor()
can determine if value is a constructor.
import { isConstructor } from "@aedart/support/reflections";
isConstructor(null); // false
isConstructor({}); // false
isConstructor([]); // false
isConstructor(() => {}); // false
isConstructor(function() {}); // true
isConstructor(class {}); // true
// Built-in objects
isConstructor(Array); // true
isConstructor(String); // true
isConstructor(Number); // true
isConstructor(Date); // true
isConstructor(Map); // true
isConstructor(Set); // true
// ...etc
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 isClassConstructor()
.