# proxy-class-new

> A 'not too bad' alternative to @ungap/new proposal

Latest version **0.1.1** (published 2023-08-08) · ISC license · 0 weekly downloads

## Install

```sh
npm install proxy-class-new
pnpm add proxy-class-new
yarn add proxy-class-new
bun add proxy-class-new
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2023-08-08 |
| First published | 2023-08-08 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 3.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Andrea Giammarchi |
| Maintainers | webreflection |
| Keywords | proxy, get, new, trap |

## Links

- npm: https://www.npmjs.com/package/proxy-class-new
- Repository: https://github.com/WebReflection/proxy-class-new
- Homepage: https://github.com/WebReflection/proxy-class-new#readme
- Issues: https://github.com/WebReflection/proxy-class-new/issues
- npm.io page: https://npm.io/package/proxy-class-new

## Alternatives

- [@sveltejs/kit](https://npm.io/package/@sveltejs/kit.md) — 2.2M weekly downloads
- [@atlaskit/theme](https://npm.io/package/@atlaskit/theme.md) — 402.0K weekly downloads
- [@tangle-network/brand](https://npm.io/package/@tangle-network/brand.md) — 10.0K weekly downloads
- [seneca](https://npm.io/package/seneca.md) — 7.4K weekly downloads
- [@bsb/base](https://npm.io/package/@bsb/base.md) — 7.2K weekly downloads

## Recent versions

- 0.1.1 (latest) — 2023-08-08
- 0.1.0 — 2023-08-08
- 0.0.0 — 2023-08-08

## README

# proxy-class-new

This module is a less powerful and slightly more error prone alternative to the [@ungap/new](https://github.com/ungap/new#readme) proposal.

It provides a *Proxy* `get` trap that returns `undefined` or a `function`, in case the intent is to provide a way to instantiate `Class.new(...args)` in the wild.

See [this TC39 proposal](https://es.discourse.group/t/function-prototype-new/1772) to know more.

```js
import newClass from 'proxy-class-new';

const Class = new Proxy(class {}, {
  get(target, name) {
    return newClass(target, name) || target[name];
  }
});

Class.new() instanceof Class; // true
```

The default export returns a function that does the following checks in an unobtrusive way:

  * the `name` is identical to `"new"` string
  * the `typeof target` is exactly `"function"`
  * no `"new" in target` exists already

If these requirements are fulfilled, an always same function able to be used to instantiate the instance is returned, otherwise the returned value is *undefined*.

---
_Source: https://npm.io/package/proxy-class-new · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
