CrxOop CrxOop: Bringing Object Oriented Programming, and Proper Prototype Based Programming, To Javascript
The aim of the library documented below is to provide developers with a solution to allow development using interfaces and classes as they are known in other object oriented programming (OOP) languages such as C++, C#, Java and PHP. Further more, V1.4 introduces structures, a generalization of the concept of prototypal inheritance, known here as POBP.
Subject
Body*
Email
SUBMIT CLOSE
Menu

8.0 Uitility Functions

CrxOop provides utility functions to help in developing with it. These utility functions are not to be confused with general utility functions that can be replaced wih similar functions from other libraries. These functions perform tasks in relation to CrxOop.

8.1 crxOop.bindFunction

crxOop.bindFunction() is a more general form of the javascript bind function, that should work on older browsers as well. crxOop.bindFunction() allows you to fine tune the bind result. Functions bound with crxOop.bindFunction() are aware of the internal CrxOop halt signal, and can also be protected from double binding, as well as other things.

crxOop.bindFunction(Function, This, IsToProtectFromDoubleBinding, IsToSetPrototype, Length, BoundArguments)
Function
Function
The function to bind.
This
Object
The value to be set for the function as its 'this'.
IsToProtectFromDoubleBinding
Boolean
If set to true, the function is protected from double binding. This means if the function returned by crxOop.bindFunction() is passed again with the same This, IsToSetPrototype, Length and BoundArguments, the function is simply returned without binding again.
Defaults to false.
IsToSetPrototype
Boolean
If set to true, the returned function retains the prototype behavior of the passed in function. This means that the returned function can be used with the javascript new operator acting as if new was called on the passed in function.
Default to false.
Length
Integer
The resulting length of the returned function. A number from -1 to 10 inclusively. If zero is passed, no value is set for length. If -1 is passed, the value is set by infering from the length of the passed in function, and the length of BoundArguments.
Defaults to 0.
BoundArguments
Array
Array of arguments to prepend to the arguments passed to the returned function before it calls the passed in function. See the javascript bind function.
Defaults to null.
Return
Object
A function
Example
//   To create a replacement roughly equivilant to the built in
//      bind function when it is not available, one could use:
if(!Function.prototype.bind)
{
   Function.prototype.bind = function(pThis)
   {
      return crxOop.bindFunction(this,
            pThis, false, true, -1,
            Array.prototype.slice.call(arguments, 1));
   };
}

8.2 crxOop.var

crxOop.var() takes a single parameter, and if the parameter is not a function, returns it. If it is a function, it returns the function such as its 'this' is set to null. Internaly, crxOop.var() uses crxOop.bindFunction(), and will only bind the function if has not been bound to null before using crxOop.var() or crxOop.bindFunction(). If crxOop.var() binds the function, it does it by making the call crxOop.bindFunction(passedInParameter, null, false, true, -1, null).

crxOop.var(variable)
variable
Mixed
Mixed input.
Return
Mixed
Either the mixed first parameter as is, or a bound function if the parameter was a function

8.3 crxOop.setTimeout

Equivilant to the javascript setTimeout function, with the added benefit that the timeout will not fire if CrxOop halts.

8.4 crxOop.setInterval

Equivilant to the javascript setInterval function, with the added benefit that the interval will halt if CrxOop halts.