Add isClass
function
#228
Closed
aleclarson
started this conversation in
Ideas
Replies: 1 comment
-
In progress at #239 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The
isClass
type guard would check for a function that must be called with thenew
operator. It would only check for native JavaScript classes, not old-schoolfunction MyClass() {}
definitions. This is a fine concession, since such old-school classes are very uncommon, and they typically check for the existence ofthis
and do a recursivenew
call ifthis
is an unexpected value.In my own type guard library, I implemented
isClass
like this:The only time this breaks is if you're compiling down to an ES target that doesn't support native
class
syntax (ES5 and below). We should recommend not usingisClass
if you plan on targeting such an environment, but Radashi only supports ES2017+, so adding such anisClass
implementation is acceptable.Beta Was this translation helpful? Give feedback.
All reactions