Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

newify

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

newify

Call function constructors with an array of arguments that spread

  • 1.1.9
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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

Keywords

FAQs

Package last updated on 22 Jul 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc