juof
For objects and functions manipulation in javascript. Use for inheritance, attribute etc.
Installation
$ npm install juof
Usage
var juof = require('juof');
function Person(name) {
this.name = name;
}
function Male (name) {
this.super(name);
this.gender = "M";
}
Person = juof.abstract(Person);
Male = juof.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
juof.abstract(type)
Parameters:
juof.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.
juof.type
The object from which the related methods are handled.
juof.type.derived(type, base)
Checking that the type is derived from the base.
Parameters:
-
type
: Type to be used.
-
base
: Inherited type.
juof.type.clone(type)
Cloning with all the features of a type.
Parameters:
juof.attribute
Used to manage operations before or after functions.
juof.attribute.inherit(attr)
Used to create a new attribute.
Parameters:
attr
: Constructor function of the attribute to be derived.
juof.attribute.bind(func, attr, ...attr)
Used to bind the attribute with the function.
Parameters:
juof.attribute.getAppliedAttributes(scope, attr)
Used to get the applied attributes of a variable.
Parameters:
juof.attribute.getBoundAttributes(func, attr)
Used to get the applied attributes of a function.
Parameters:
juof.attribute.getAttributeResult(scope)
Used to get the result of the applied attributes to variable.
Parameters:
scope
: The variable that attributes are applied to.
juof.function
Used to add tags to functions and to preserve the original form after manipulation.
juof.function.create(query, fn)
Create a new instance of JuFunction. Return instance of JuFunction.
Parameters:
Or
juof.function.create(fn)
Parameters:
juof.function.define(scope, query, fn)
Create a new instance of JuFunction and define a field by function name into scope object. Return instance of JuFunction.
Parameters:
-
scope
: Object that is defined a field by function name into.
-
query
: String query of tags. Example: "number:0;boolean:true;string:text;array:one,two"
-
fn
: Original function. Function that must be named. Example;
juof.function.define(scope, query, function test() { });
Or
juof.function.define(scope, fn)
Parameters:
juof.function.each(scope, eachFn)
Function that do forEach instances of JuFunction in the scope object.
Parameters:
eachFn(instance)
juof.function.each(scope, function (instance) { ... })
Parameters:
instance
: Instance of JuFunction.
instance of JuFunction
Fields:
-
tags
: Object of tags.
-
scope
: Object that is defined a field by function name into or bound object to function.
-
name
: Original function name.
-
query
: String query of tags.
-
function
: Manipulated function.
-
original
: Original function.
Prototypes:
-
bind
: Runs as same in bind prototype of Function but available multiple times.
-
apply
: Runs as same in apply prototype of Function.
-
call
: Runs as same in call prototype of Function.
-
run
: Runs the manipulated function.
-
pure
: Runs the original function.
-
value
: Manipulate function and manipulated function.
Changelog
All notable changes to this project will be documented in this file.
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.