instsure

0.2.1 • Public • Published

Instsure

Build Status Coverage Status Slack Status Version Downloads Node License

Instsure is a function wrapper to ensure the object initialitation, preventing wrong callings to the constructor function without right context.

NPM GRID

Installation

Install with npm install instsure --save.

Usage

To use, add the require node module or use browserify if you want to use in a browser:

 
    // Wrapper Function
 
    const Instsure = require('instsure');
 
    var ConstructorWrapFoo = Instsure(function() {
        this.args = arguments;
        this.context = this;
    });
 
    ConstructorWrapFoo.prototype.foo = 'bar'
 
    var instance = new ConstWrapFoo(1,2,3,4),
        // or
        instance = ConstWrapFoo(1,2,3,4),
        // or
        instance = ConstWrapFoo.new([1,2,3,4]);
 
        console.log(instance.args) // [1,2,3,4];
 
        console.log(instance instanceof ConstWrapFoo); // true
 
    // Existing Constructor
 
    const Instsure = require('instsure');
 
    var ConstructorFoo = function() {
        this.args = arguments;
        this.context = this;
    };
 
    ConstructorWrapFoo.prototype.foo = 'bar'
 
    var instance = new Instsure(ConstructorFoo)(1,2,3,4),
        // or
        instance = Instsure(ConstructorFoo)(1,2,3,4),
        // or
        instance = Instsure(ConstructorFoo).new([1,2,3,4]);
 
        console.log(instance.args) // [1,2,3,4];
 
        console.log(instance instanceof ConstructorFoo); // true
 
        console.log(instance instanceof ConstructorWrapFoo); // true

WTF

Readme

Keywords

none

Package Sidebar

Install

npm i instsure

Weekly Downloads

2

Version

0.2.1

License

none

Last publish

Collaborators

  • rubeniskov