is-subclass-of

1.0.1 • Public • Published

is-subclass-of

Returns true if A is a subclass of B.

Installation

Requires Node.js 6.0.0 or above.

npm i is-subclass-of

API

The module exports a single function.

Parameters

  1. Bindable: A (function): What may or may not be a subclass of B.
  2. B (function or string): What may or may not be an ancestor of A. You can either provide the class itself or its string name.

Return Value

  • Returns true if A is a subclass of B.
  • Otherwise false.

Example

const isSubclassOf = require('is-subclass-of')

isSubclassOf(Date, Error) // false
isSubclassOf(Error, Error) // false

isSubclassOf(TypeError, Error) // true
isSubclassOf(RangeError, Error) // true
isSubclassOf(RangeError, 'Error') // true

class A {}
class B extends A {}
isSubclassOf(A, A) // false
isSubclassOf(B, A) // true
isSubclassOf(B, 'A') // true

// Supports the bind operator
TypeError::isSubclassOf(Error) // true
TypeError::isSubclassOf('Error') // true
B::isSubclassOf(A) // true

Related

  • is-class-of: Returns true if A is a subclass of B or the same class as B.
  • is-instance-of: Like instanceof, but uses class name strings.

Readme

Keywords

Package Sidebar

Install

npm i is-subclass-of

Weekly Downloads

2

Version

1.0.1

License

MIT

Unpacked Size

3.25 kB

Total Files

4

Last publish

Collaborators

  • lamansky