1.0.3 • Published 6 years ago

jujsoop v1.0.3

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

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";
}

// Change the person class to person abtraction.
Person = juoop.abstract(Person);

// The male class inherits from the person class.
Male = juoop.inherit(Male, Person);

// Add prototype to the person class.
Person.prototype.cv = function () {
    console.log("Person.prototype.cv");
    console.log("Name: " + this.name);
}

// The male class shows the cv prototype of the person class.
new Male("JosephUz").cv();

// Override the cv prototype of the male class. 
Male.prototype.cv = function () {
    console.log("Male.prototype.cv");
    console.log("Name: " + this.name + '\nGender: ' + this.gender);
}

// The male class shows own cv prototype.
new Male("JosephUz").cv();

Methods

juoop.abstract(type)

Parameters:

  • type: Type to be used.

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:

  • type: Type to be used.

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:

  • func: Function to which the attribute will be bound.

  • attr: Constructor function of the derived attribute. Multiple attributes can be written as parameters at the same bind process.

juoop.attribute.getAppliedAttributes(scope, attr)

Used to get the applied attributes of a variable.

Parameters:

  • scope: The variable that attributes are applied to.

  • attr: Optional attribute parameter that is used to get the value of the attribute.

juoop.attribute.getBoundAttributes(func, attr)

Used to get the applied attributes of a function.

Parameters:

  • func: The function that attributes are bound to.

  • attr: Optional attribute parameter that is used to get the value of the attribute.

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

Basic Usage

This example shows the most basic way of usage.

Attribute 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.

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago