Skip to content

Latest commit

 

History

History
28 lines (19 loc) · 737 Bytes

constructor.md

File metadata and controls

28 lines (19 loc) · 737 Bytes

Constructor

A Function instance that's a constructor (either regular function or class)

constructor/is

Confirms if given object is a constructor function_

const isConstructor = require("type/constructor/is");

isConstructor(function () {}); // true
isConstructor(() => {}); // false
isConstructor(class {}); // true
isConstructor("foo"); // false

constructor/ensure

If given argument is a constructor function, it is returned back. Otherwise TypeError is thrown.

const ensureConstructor = require("type/constructor/ensure");

const fn = function () {};
ensureConstructor(fn); // fn
ensureConstructor(() => {}); // Thrown TypeError: () => {} is not a constructor function