Skip to content

Commit

Permalink
Add docs for isConstructor()
Browse files Browse the repository at this point in the history
  • Loading branch information
aedart committed Jan 30, 2024
1 parent 0e0f9aa commit f62acc9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/.vuepress/archive/Version0x.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export default PagesCollection.make('v0.x', '/v0x', [
'packages/support/install',
'packages/support/meta',
'packages/support/objects',
'packages/support/reflections',
'packages/support/misc',
]
},
Expand Down
31 changes: 31 additions & 0 deletions docs/archive/current/packages/support/reflections.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
title: Reflections
description: Reflection utilities
sidebarDepth: 0
---

# Reflections <Badge type="tip" text="Available since v0.7" vertical="middle" />

The `@aedart/support/reflections` submodule offers a few reflection related utilities.

[[TOC]]

## `isConstructor`

Based on the [TC39 `Function.isCallable() / Function.isConstructor()`](https://github.com/caitp/TC39-Proposals/blob/trunk/tc39-reflect-isconstructor-iscallable.md) proposal, the `isConstructor()` can determine if given argument is a constructor.

```js{6,8-9}
import { isConstructor } from "@aedart/support/reflections";
isConstructor(null); // false
isConstructor({}); // false
isConstructor([]); // false
isConstructor(function() {}); // true
isConstructor(() => {}); // false
isConstructor(Array); // true
isConstructor(class {}); // true
```

**Acknowledgement**

The source code of the above shown methods is heavily inspired by Denis Pushkarev's Core-js implementation of the [Function.isCallable / Function.isConstructor](https://github.com/zloirock/core-js#function-iscallable-isconstructor-) proposal (_License MIT_).

0 comments on commit f62acc9

Please sign in to comment.