-
-
Notifications
You must be signed in to change notification settings - Fork 0
class
Nicholas Berlette edited this page Jun 19, 2025
·
1 revision
function isClass<
T,
A extends readonly unknown[] = readonly any[],
P extends object | null = Is<T, object | null>,
>(it: unknown): it is Class<T, A, P>;Checks if a given value is a constructor function, also known as a class.
This includes all pure functions - no generators, arrow functions, or
getters/setters - that also have an own prototype propertty which is a
non-null object. The prototype must have an own constructor property that
points back to the class constructor function itself. Lastly, the function's
source code is inspected for the class keyword, to ensure that it is a class
and not just a regular function.
| Name | Info |
|---|---|
it |
The value to check. |
true if the value is a class, false otherwise.
Objects
import { isClass } from "jsr:@nick/is/class";
class Foo {}
console.log(isClass(Foo)); // true
const Bar = function () {
this.foo = "bar";
return this;
};
console.log(isClass(Bar)); // false
const Baz = () => {};
console.log(isClass(Baz)); // falseTypes
import { isClass } from "jsr:@nick/is/class";
class Foo {}
console.log(isClass(Foo)); // true
const Bar = function () {
this.foo = "bar";
return this;
};
console.log(isClass(Bar)); // false
const Baz = () => {};
console.log(isClass(Baz)); // false-
T(default:any) -
Aextendsreadonly unknown[](default:readonly any[]) -
Pextendsobject | null(default:Is<T, object | null>)
readonly prototype: P;