New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

construct-new

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

construct-new

Like the new operator, but a function.

latest
Source
npmnpm
Version
2.0.10
Version published
Maintainers
1
Created
Source

construct-new

Like the new operator, but as a function for convenience and familiarity.

Usage

What you would normally do:

class Foo {
  constructor(name) {
    this.name = name
  }
  print() {
    console.log("Hi, I am " + this.name)
  }
}
const myFoo = new Foo("bar")
myFoo.print() // output: Hi, I am bar

What you would do with this:

const construct = require('construct-new')
class Foo {
  constructor(name) {
    this.name = name
  }
  print() {
    console.log("Hi, I am " + this.name)
  }
}
const myFoo = construct({
  target: Foo,
  args: ["bar"]
})

myFoo.print() // Hi, I am bar

or

construct({
  target: Foo,
  args: ["bar"],
  callback: (myFoo) => {
    myFoo.print() // Hi, I am bar
  }
})

If the class doesn't take any arguments, you don't have to pass in the args property, it will still work like the args is an empty array.

Keywords

instance

FAQs

Package last updated on 12 Mar 2026

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