Classing{js}: API Summery

Function.create
Function.create(mode , overloads)
mode Boolean

The mode of Overloading :typed or non-typed.true for typed , false for non-typed

overloads Array

an array containing the overloads.

returns Function

the overloaded function

Notes:

  • In non-typed overloading, the overloads array is an array of functions.
  • In typed overloading, an instance takes two elements in the overloads array : the first is for the type list (using types), and the second is for the function itself.
  • Instead of passing true or false to the mode parameter, you can pass xTyped or xNonTyped.

Example:

var Add = Function.create(xNonTyped , [
	function(a,b){return a + b;},
	function(a,b,c){return a + b + c;}
]);
						

types
classing.types(c1 , c2 , c3 , ...)
types(c1 , c2 , c3 , ...)
ci Function

the constructor function of the type (either native or custom)

returns _xTypes Object

the type list object to be passed to Function.create

Notes:

  • Native, custom constructor functions with a name and Classes are recognized.
  • Custom anonymous constructor function must be stamped to be recognized.
  • In copy constructors, use xSelf to point to the class being created.

Example:

var Add = Function.create(xTyped , [
	types(Number,Number),
	function(a,b) { return a + b}
]);
						

xStamp
classing.xStamp(Constructor)
Constructor Function

the custom constructor function to be stamped for recognition

returns void

Example:

var Complex = function(re , img) {
	this.re = re; this.img = img;}
classing.xStamp(Complex);
var Add = Function.create(xTyped , [
	types(Complex,Complex),function(Z,W){
		return new Complex(Z.re + W.re,Z.img + W.img);
	}
]);
						

Class
classing.Class(defintion)
defintion Object

The defintion of the class

returns _classPattern Function

the created class

Notes:

  • The proprties names of the defintion object are one, two or all of the following: private,protected and public(which are the access modifiers).
  • Each access modifier is itself an object whose proprties are the class components having that accces level.

Example:

var Person = classing.Class({
	public : { name : "John Doe"}
});
						

Static
classing.Static(component)
Static(component)
component unspecific

the component to be marked static.

returns Object

an object wrapping the component and marked with an isStatic property.

Example:

var Person = Class({
	public: {
		counter : Static(0),
		Construct: function(){Person.counter++;}
	}
})
						

Final
classing.Final(method)
Final(method)
method Function

The function to be marked as final

returns Function

The marked function

Example:

var Visitor  = Class({
	private : { id : null},
	public: {
		Construct : function() { this.id = Date.now();},
		getId : Final(function(){return this.id;})
	}
})
						

Final.Class
classing.Final.Class
returns Function

The Class function

Notes:

  • This marks the class final (unextensible).

Example:

var Infertile = classing.Final.Class({
	public : {name : null}
})
						

Abstract
classing.Abstract(method)
Abstract(method)
method Function

The function to be marked abstract.

returns Function

The marked function.

Notes:

  • An abstract function must be inside an abstract class
  • The body of the argumnt method must be empty. if it's an overloaded function, all the instances must have empty bodies.

Example:

var Child = classing.Abstract.Class({
	public: { Play : Abstract(function(){}) }
});
						

Abstract.Class
classing.Abstract.Class
returns Function

The Class function

Notes:

  • Marks the class as abstract. It must have at least one Abstract function.

Example:

var Shape = classing.Abstract.Class({
	public : { Area : Abstract(function(){})}
});
						

Class.Extends
classing.Class.Extends(Parent)
Parent _classPattern Function

The parent class

returns Function

The Class function.

Notes:

  • To access the parent object, use the base keyword.
  • Example:

    var Child = classing.Class.Extends(Parent)({
    	public : {
    		newFunc : function(){ return "function of child"; }
    	}
    });
    						

    Interface
    classing.Interface(defintion)
    defintion Object

    The defintion of the interface.

    returns Object

    The Object represinting the interface

    Notes:

    • Each proprty in the defintion object is a function with empty body. if it's an overloaded function, all the instances must have empty bodies.
    • All methods of an interface are public.

    Example:

    var IPayable = classing.Interface({
    	getPaid : function()
    })
    						

    Class.Implements
    classing.Class.Implements(i1,i2,...)
    ij Object

    an interface to be implemented.

    returns Function

    The Class function.

    Notes:

  • The following order of extending and implementing is forced:
  • Class.Extends(...).Implements(...)

    Example:

    var Employee = classing.Class.Implements(IPayable)({
    	public: {getPaid : function(){return "$5000.00"}}
    })
    						

    Object::instanceOf
    Object::instanceOf(ancestor)
    ancestor Function/Object

    The Class or Interface to check if the object is instance of it.

    returns Boolean

    true of the object is instance of ancstor. false otherwise.

    Notes:

  • All instances of Object (which is exaclty every object you make) will have the instanceOf method.
  • Eaxmple:

    var IVoid = classing.Interface({ func : function(){} });
    var Parent = classing.Class({});
    var Child = classing.Class.Extends(Parent).Implements(IVoid)({
    	public : { func : function(){return "void";} }
    });
    var obj = new Child();
    obj.instanceOf(Child); //true
    obj.instanceOf(Parent); //true
    obj.instanceOf(IVoid); //true;
    obj.instanceOf(Object); //true; 
    						
    ^