Skip to content

Function: objectParentConstructors() ​

Call Signature ​

objectParentConstructors<ClassConstructor>(target): Function[]

Get the ancestors of a class: its parent, the parent's parent, and so on.

Type Parameters ​

ClassConstructor ​

ClassConstructor extends Function

Parameters ​

target ​

ClassConstructor

A class. The types only accept a class, but an object passed with a cast gives its class's ancestors.

Returns ​

Function[]

The ancestor classes, the nearest first, without the class itself and without Object; an empty array for a class which extends nothing.

Example ​

typescript
import {objectParentConstructors} from 'lakutata/utils'

class Entity {
}

class User extends Entity {
}

class Admin extends User {
}

console.log(objectParentConstructors(Admin).map((parent: Function): string => parent.name))
//['User', 'Entity']

Call Signature ​

objectParentConstructors<ClassPrototype>(target): Function[]

Get the ancestors of a class: its parent, the parent's parent, and so on.

Type Parameters ​

ClassPrototype ​

ClassPrototype extends Object

Parameters ​

target ​

IConstructor<ClassPrototype>

A class. The types only accept a class, but an object passed with a cast gives its class's ancestors.

Returns ​

Function[]

The ancestor classes, the nearest first, without the class itself and without Object; an empty array for a class which extends nothing.

Example ​

typescript
import {objectParentConstructors} from 'lakutata/utils'

class Entity {
}

class User extends Entity {
}

class Admin extends User {
}

console.log(objectParentConstructors(Admin).map((parent: Function): string => parent.name))
//['User', 'Entity']

Released under the MIT License.