# instantiate

> Instantiate a Javascript Object from an array of arguments or from arguments

Latest version **0.1.4** (published 2014-02-19) · 0 weekly downloads

## Install

```sh
npm install instantiate
pnpm add instantiate
yarn add instantiate
bun add instantiate
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.4 |
| Published | 2014-02-19 |
| First published | 2013-08-07 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=8.0 |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Michael Hernandez |
| Maintainers | mhernandez |
| Keywords | Objects, instantiation, arguments, args, .call, .apply |

## Links

- npm: https://www.npmjs.com/package/instantiate
- Repository: http://github.com/miketheprogrammer/instantiate
- Homepage: https://github.com/miketheprogrammer/instantiate
- Issues: https://github.com/miketheprogrammer/instantiate/issues
- npm.io page: https://npm.io/package/instantiate

## Dependencies (1)

- [tape](https://npm.io/package/tape.md) ~2.4.2

## Recent versions

- 0.1.4 (latest) — 2014-02-19
- 0.1.3 — 2014-02-19
- 0.1.1 — 2013-08-12
- 0.1.0 — 2013-08-07

## README

instantiate
===========

Instantiate a Javascript Object from an array of arguments

[![browser support](https://ci.testling.com/miketheprogrammer/instantiate.png)](https://ci.testling.com/miketheprogrammer/instantiate)


[![build status](https://secure.travis-ci.org/miketheprogrammer/instantiate.png)](http://travis-ci.org/miketheprogrammer/instantiate)



Installation
========
````javascript
npm install instantiate
````

Usage
========
This module provides a usefull methods and a usefull abstraction to instantiating objects from either arrays, or the default method of providing arguments.

instantiate.fromArray ( obj, arrayOfArgs )
-----------
var instanceOfObject = instantiate.fromArray(obj, arrayOfArgs);

````javascript
var instanceOfObject = instantiate.fromArray(obj, [1,2,3])

````

instantiate.fromArguments ( obj )
-----------
var instanceOfObject = instantiate.fromArguments(obj, argumentA, argumentB, argumentC, ...);

````javascript
var instanceOfObject = instantiate.fromArguments(obj, 1, 2, 3)

````

instantiate.new ( obj )
-----------
Abstraction of both fromArray and fromArguments.
Should work for most cases. Works by detecting if there is a 3rd argument in arguments or not.

Refer to tests.js -- included here for ease.

````javascript
var instantiate = require('../index');
var test = require('tap').test;

var obj = function (a,b,c) {
    this.a = a;
    this.b = b;
    this.c = c;
}
test('instances of objects Should be returned', function(t) {
    t.plan(4);
    t.ok(instantiate.fromArray(obj, [1,2,3]) instanceof obj)
    t.ok(instantiate.fromArguments(obj,1,2,3) instanceof obj)
    t.ok(instantiate.new(obj, [1,2,3]) instanceof obj)
    t.ok(instantiate.new(obj,1,2,3) instanceof obj)
    
});

test('instances have proper values', function(t) {
    t.plan(12);
    var instances = [
        instantiate.fromArray(obj, [1,2,3]),
        instantiate.fromArguments(obj, 1, 2, 3),
        instantiate.new(obj, [1,2,3]),
        instantiate.new(obj, 1, 2, 3)
    ];
    
    for ( i in instances ) {
        var ins = instances[i];
        t.same(ins.a, 1);
        t.same(ins.b, 2);
        t.same(ins.c, 3);
    }
});

````

---
_Source: https://npm.io/package/instantiate · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
