UNPKG

780 BJavaScriptView Raw
1// Copyright 2017-2022 @polkadot/util authors & contributors
2// SPDX-License-Identifier: Apache-2.0
3
4/**
5 * @name isChildClass
6 * @summary Tests if the child extends the parent Class
7 * @description
8 * Checks to see if the child Class extends the parent Class
9 * @example
10 * <BR>
11 *
12 * ```javascript
13 * import { isChildClass } from '@polkadot/util';
14 *
15 * console.log('isChildClass', isChildClass(BN, BN); // => true
16 * console.log('isChildClass', isChildClass(BN, Uint8Array); // => false
17 * ```
18 */
19export function isChildClass(Parent, Child) {
20 // https://stackoverflow.com/questions/30993434/check-if-a-constructor-inherits-another-in-es6/30993664
21 return Child // eslint-disable-next-line no-prototype-builtins
22 ? Parent === Child || Parent.isPrototypeOf(Child) : false;
23}
\No newline at end of file