ju JsOOP
For inheritance in javascript.
Installation
$ npm install jujsoop
Usage
var juoop = require('jujsoop');
function Person(name) {
this.name = name;
}
function Male (name) {
this.gender = "M";
}
Person = juoop.abstract(Person);
Male = juoop.inherit(Male, Person);
Person.prototype.cv = function () {
console.log("Person.prototype.cv");
console.log("Name: " + this.name);
}
new Male("JosephUz").cv();
Male.prototype.cv = function () {
console.log("Male.prototype.cv");
console.log("Name: " + this.name + '\nGender: ' + this.gender);
}
new Male("JosephUz").cv();
Methods
juoop.abstract(type)
Parameters:
juoop.inherit(type, base)
Anymore, when creating a new instance of type, the last parameter of constructor will be base and in the same way the last parameter of base constructor will be type. Also, type constructor can only be called with "new" keyword or when base constructor has no returns. However, base constructor is always called.
Parameters:
-
type
: Type to be used.
-
base
: Inherited type.
juoop.type
The object from which the related methods are handled.
juoop.type.derived(type, base)
Checking that the type is derived from the base.
Parameters:
-
type
: Type to be used.
-
base
: Inherited type.
juoop.type.clone(type)
Cloning with all the features of a type.
Parameters:
juoop.attribute
Used to manage operations before or after functions.
juoop.attribute.inherit(attr)
Used to create a new attribute.
Parameters:
attr
: Constructor function of the attribute to be derived.
juoop.attribute.bind(func, attr, ...attr)
Used to bind the attribute with the function.
Parameters:
juoop.attribute.getAppliedAttributes(scope, attr)
Used to get the applied attributes of a variable.
Parameters:
juoop.attribute.getBoundAttributes(func, attr)
Used to get the applied attributes of a function.
Parameters:
juoop.attribute.getAttributeResult(scope)
Used to get the result of the applied attributes to variable.
Parameters:
scope
: The variable that attributes are applied to.
Examples
This example shows the most basic way of usage.
This example shows a way of the attribute usage.
License
This software is free to use under the JosephUz. See the LICENSE file for license text and copyright information.