0.1.1 • Published 9 months ago

proxy-class-new v0.1.1

Weekly downloads
-
License
ISC
Repository
github
Last release
9 months ago

proxy-class-new

This module is a less powerful and slightly more error prone alternative to the @ungap/new 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 to know more.

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.

0.1.1

9 months ago

0.1.0

9 months ago

0.0.0

9 months ago