AOOP
Augmented Object Oriented Programming This node module allow programmers to use some of Object Oriented tecniques on JavaScript (Prototype Oriented)
Getting Started
Installing
For install library is easy to install by cloning the repo. You can install trhought npm too: Local installation
npm install aoop
Global installation
npm install -g aoop
Usage
- Require
const aoop = ; //aoop module contains this elements://{// Mixin:[Function],// Interface:[Function],// Utils:{// copyProto:[Function],// copyAsProto: [Function],// extend: [Function],// getProto: [Function],// isClass: [Function]// }//}
- Mixin
Mixin(class A,class B,[... classes])
This function takes all methods from two or more classes (or constructor functions) and create another one that inherits all of them from the mixins classes. Remember that the hierarchy of inheritance goes from left to right
const Mixin = ; //creating two classes A and B//class A created as constructor function{}Aprototype{console;};Aprototype{console;}; //class B created as ES6 class {console;} {console;} //USING MIXIN//class C created as classconst C = AB;//class D created as ES6 classBA{} //TESTING INSTANCESvar c = ;var d = ; c; //fooc; //barc; //Baz from A! (the Mixin(A,B) takes A > B hierachy) d; //food; //bard; //Baz from B! (the Mixin(B,A) takes B > A hierachy)
- Interface
Interface(proto, constrain)
This function constrain a constructor of a class (or a particular object) to have some methods defined in the proto
argument. constrain
argument tell the Interface to instanciate methods from his proto
to the extended class.
You can create an object from an Interface too using default methods described in the Interface proto
. The Interface's instance constructor take a force
argument to tell the instance to use Interface's proto
defaults methods.
const Interface Utils = ; //Creating Interface that must have "bye" methodvar proto = {console};const Hello = proto; //as Function without "bye" method{Hello;}Utils; //as Function with "bye" method{Hello;}Utils;Bprototype{console;}; //as Function with defaults methods (passing "force" argument to Hello Interface){Hello;}Utils; //as class without "bye" method{} //as class with "bye" method{console;} //as class with Hello defaults methods (passing "force" argument to Hello Interface){supertrue;} var a = ; //throw an InterfaceError becaues is missing "bye" methodvar b = ;var c = ;var d = ; //throw an InterfaceError becaues is missing "bye" methodvar e = ;var f = ;var h = true; //generate an Interface instance by passing true as "force" argument b; //good bye from Bc; //good bye from Helloe; //good bye from Ef; //good bye from Helloh; //good bye from Hello
-
Utils This object is a library of some tools for deal with functions.
-
copyProto(A,B)
: get and copy the prototype of B to A -
copyAsProto(A,B)
: copy directly object B to A as prototype object -
extend(A,B)
: extend the A function with prototype of B -
getProto(A)
: return the correct proto of the function A -
isClass(A)
: returntrue
if the A function is an ES6 class object orfalse
if it is a normal JavaScript function
-
Contacts
If you like the project feel free to contact me on my .
Something gone wrong? Feel free to rise an issue!
Did you like this project and it was usefull? Help me improve my work: