Bunoon: TESS | Manual | Class

Have you ever got sick and tired of the fact that Javascript does not have built-in Class support? Have you found that even if you try and write your own, you cannot inherit from other class objects easily, or even multiple objects? Well, all this is a thing of the past, as this section offers functions that will create custom classes for you, offing support for initialize functions and inheritance (either single or multiple).

Once you have created your classes, there are some additional functions that you may find useful, like extending an existing class with the variables and functions of another. You can also extract all the functions and variables from an existing class and assign them to a desired Javascript scope.

Generates a Class, supporting constructors and inheritance.

The main arguments for this function are as follows:

  • oProperties [Object] - An object containing the functions, inherit object, constructor, variables and functions.

The return value for this function is as follows:

  • [Object] - A new class object (or null if any error has occurred).

Below is an example of how to use this function (single inheritance):

var oClass1 = new $T.Class.New({

FirstHello: function () {

alert("First Hello!");

}

});


var oClass2 = new $T.Class.New({

_inherit_: oClass1,

_initialize_: function () {

this.FirstHello();

this.SecondHello();

},

SecondHello: function () {

alert("Second Hello!");

}

});

Below is an example of how to use this function (multiple inheritance):

var oClass1 = new $T.Class.New({

FirstHello: function () {

alert("First Hello!");

}

});


var oClass2 = new $T.Class.New({

_inherit_: oClass1,

SecondHello: function () {

alert("Second Hello!");

}

});


var oClass3 = new $T.Class.New({

_inherit_: [oClass1, oClass2],

_initialize_: function () {

this.FirstHello();

this.SecondHello();

this.ThirdHello();

},

ThirdHello: function () {

alert("Third Hello!");

}

});

Takes a list of classes that have been passed into the arguments and combines them into a new class.

The main arguments for this function are as follows:

  • [arguments] - An arguments object array containing the list of classes to combine.

The return value for this function is as follows:

  • [Object] - A new combined class object (or null if any error has occurred).

Below is an example of how to use this function:

var oClass1 = new $T.Class.New({

FirstHello: function () {

alert("First Hello!");

}

});


var oClass2 = new $T.Class.New({

SecondHello: function () {

alert("Second Hello!");

}

});


var oNewClass = $T.Class.Combined(oClass1, oClass2);

Takes the variables and functions from a class and pulls them into a desired scope.

The main arguments for this function are as follows:

  • oClass [Object] - The class that we should pull the variables and functions from.
  • oScope [Object] - The scope area where the variables and functions should be defined (defaults to window).
  • bDeleteOriginals [Boolean] - States if the original variables and functions in the class object should be deleted (defaults to false).

The return value for this function is as follows:

  • [Boolean] - A boolean of true/false to state of we have completed the operation.

Below is an example of how to use this function:

var oClass = new $T.Class.New({

FirstHello: function () {

alert("First Hello!");

},

SecondHello: function () {

alert("Second Hello!");

}

});


function AreaScope () {

$T.Class.Pull(oClass, this);

}

Extends a class with the variables and functions from a list of other classes (in arguments).

The main arguments for this function are as follows:

  • oClass [Object] - The class that we should be extending.
  • [arguments] - An arguments object array containing the list of classes to pull the functions and variables from.

The return value for this function is as follows:

  • [Object] - The extended class object (or null if any error has occurred).

Below is an example of how to use this function:

var oClass1 = new $T.Class.New({

FirstHello: function () {

alert("First Hello!");

}

});


var oClass2 = new $T.Class.New({

SecondHello: function () {

alert("Second Hello!");

}

});


oClass1 = $T.Class.Extend(oClass1, oClass2);