编辑 | blame | 历史 | 原始文档

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