objects-mixing

0.0.1 • Public • Published

**

**

Object mixing module.

**

** This module is for mixing an objects in one super object. It uses proto property to combine objects, but not just copying properties and methods. require of this module returns function(arg). This module extends a standard Object by the method addMixin().

NOTE! In this version of the module you can't to mix objects, that are instances of the same objects

A. function(arg) - arg is a number of arguments:

  1. arrays - [constructor(, arguments, this)], where constructor is function, object constructor, arguments - array of arguments for function-constructor this - uses as this in function-constructor each of constructor creates an object by using arguments and this;
  2. objects - object;

Then all of objects, created by constructor, or passed as an argument, will be joined in one super-object, that contain all of the methods and properties of all objects. To use this module in your application you need to require("object-mixing") then use it as function(arg), for example: var objMixingFunc = require("object-mixing")(new Obj1,[constructor, arguments]);

B. addMixin() = function(arg) (see A.).

You can use addMixin() with any object in your app. For example obj1.addMixin(obj2) - and all the methods and properties of obj2 will be available through obj1.


Example of A. use-case:

var objMixingFunc = require("objects-mixing");
function cr1(myName)
{
    this.name = myName;
}
function cr2(myLastname)
{
    this.lastname = myLastname;
}
function cr3()
{
    this.sayMe = function(){
        console.log(this.name);
    };
}
function cr4()
{
    this.gggg="33";
    };
function cr5()
{
    this.Yes="88";
};
function crNext()
{
    this.func = "It works";
}
cr5();
cr1.prototype = new cr5();
cr3.prototype = new cr4();
cr2.prototype = new cr3();
var err22 = new Error("22");
var obj1 = objMixingFunc([cr1,"ME"],[cr2,"goodyTwo"],[crNext], [Error, "err", global]);
console.log(obj1);

Example of B. use-case:

var objMixingFunc = require("objects-mixing");
function objEx()
{
    this.prop1 = "objEx";
}
function objEx2()
{
    this.prop2 = "objEx2";
}
var obj1 = objMixingFunc(new Error("111"), [objEx]);
obj1.addMixin([objEx2]);

Package Sidebar

Install

npm i objects-mixing

Weekly Downloads

1

Version

0.0.1

License

ISC

Last publish

Collaborators

  • pashoo