Skip to content

Instsure is a function wrapper to ensure the object initialitation

License

Notifications You must be signed in to change notification settings

rubeniskov/instsure

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Instsure

Build Status Coverage Status Slack Status Version Downloads Node License

Issues Open Issue Resolution

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

About

Instsure is a function wrapper to ensure the object initialitation

Resources

License

Stars

Watchers

Forks

Packages

No packages published