newify

Call function constructors with an array of arguments that spread

MIT 9 个版本
安装
npm install newify
yarn add newify
pnpm add newify
bun add newify
README

Purpose

Calling function constructors with an array of arguments is difficult. Until spread params are fully supported in all browsers, newify does the job.

For a given function constructor

function Student(firstName, lastName, birthYear){
	this.firstName = firstName
	this.lastName = lastName
	this.birthYear = birthYear
}

We want to easily call the function constructor like

var arr = ['john','scot', 1980]
var s = new Student(arr) //but this will obviously not work as expected.

//we need ES6 spread
var s = new Student(...arr)

But since we can't use spread in ES5 ...

NEWIFY to the rescue!

var arr = ['john','scot', 1980]
var s = require('newify')(Student, arr)

Installation

npm install newify

Usage

As in the above example, just give newify a function and an array of args

var arr = ['john','scot', 1980]
var s = require('newify')(Student, arr)

Run tests

make test
版本列表
1.1.9 2014-07-22
1.1.8 2014-07-22
1.1.7 2014-07-22
1.1.6 2014-07-22
1.1.3 2014-07-21
1.1.2 2014-07-18
1.1.1 2014-07-18
1.1.0 2014-07-18
1.0.0 2014-07-18