disallow-new

0.0.1 • Public • Published

This is a simple utility for disallowing the use of "new" with certain functions. It's especially useful for when you have a capitalized factory function that you don't want people to use as a constructor (which would cause an unnecessary object allocation but otherwise succeed without warning).

Installation

npm install disallow-new

Usage

import disallowNew from 'disallow-new';
 
function MyFactory() {
  // [SNIP]
}
 
export default disallowNew(MyFactory);

Elsewhere:

let a = new MyFactory(); // Errors!
let a = MyFactory(); // All good.

Package Sidebar

Install

npm i disallow-new

Weekly Downloads

1

Version

0.0.1

License

MIT

Last publish

Collaborators

  • kenzic
  • lettertwo
  • hzdgadmin
  • matthewwithanm