Caplin Trader 4.0.3

Namespace: caplin

caplin

The root package for all Caplin Trader libraries that also provides a set JavaScript language extensions including namespace definition, class loading, and object-orientated programming constructs. For details of how to understand and extend Caplin classes, please see BladeRunner object-oriented JS.

The caplin package is defined by the bootstrap library.

It is necessary for the bootstrap library to be loaded before all other Caplin Trader libraries.

Methods

(static) deprecated(sClassName, sMethodName, sDate, sMessage)

Invoked by API methods that have been deprecated. If the unary parameter deprecated is included within the query string of the application web page any invocations of this method will result in an error message being displayed, making it easier to find out which deprecated methods are being used by the application. Remember that we want to be able to pull uses of this method, including the classname, the method name and the date out of our code base using a regex.
Parameters:
Name Type Description
sClassName String The name of the class that has been deprecated or the class that the deprecated method belongs to.
sMethodName String The name of the method that is deprecated. null if the whole class or constructor has been deprecated.
sDate String The date that this method was deprecated in YYYY-MM-DD format, e.g. "2012-03-20"
sMessage String A message describing the deprecation. This should explain how code that uses this method should be rewritten.

(static) extend(vSubClass, vSuperClass)

Extends the class definition of the sub class with the class definition of the super class.

Subclassing in JavaScript is done by extending the prototype of the sub class with the properties that are defined on the prototype of the super class. The properties on the super class can be any type of JavaScript object, including a standard function object, typically used as a class method, or simply an object, typically used a static member.

Parameters:
Name Type Description
vSubClass Variant The class that is extending the superclass. This can be either a reference to the class's constructor or a String representation
vSuperClass Variant The class to be extended. This can be either a reference to the class's constructor or a String representation

(static) getClass(sFullClassName, vLoadClassopt) → {function}

Returns the constructor function for a class given the fully qualified class name in string form.

This method does not actually load the class unless the bLoadClass argument is true, in which case the class is loaded synchronously
Behaviour for when the class is unknown can be defined; context:name of what needs the class, unknownClass: function returned instead. load: Boolean determining whether to attempt loading the class. singleton: Raise/throw error if the class isn't a singleton. If no unknownClass is specified an exception will be thrown, otherwise an error will be raised.

caplin.getClass('myapp.SomeClass') - Fetch a loaded class, which isn't a singleton, throw Error if not known.
caplin.getClass('myapp.SomeClass',{unknownClass:myapp.Fallback,context:'myapp'}) - Fetch loaded class, use myapp.Fallback if not known, and raise error in log.
(see caplin#include).
Parameters:
Name Type Attributes Description
sFullClassName String The full name of the class.
vLoadClass Variant <optional>
true if this method should ensure that the specified class is loaded, otherwise false. If a Map is passed details about handling of unknown class must be specified. If omitted, it will default to false
Throws:
Error if the specified class name is not a String.
Returns:
The constructor for the specified class.
Type
function

(static) getPackage(sPackageName) → {Object}

Returns the inner-most package object for the given package name string.
Parameters:
Name Type Description
sPackageName String
Returns:
the inner most package
Type
Object

(static) implement(fClass, fInterface)

Extends the class definition of fClass with the interface defined in fInterface.
Parameters:
Name Type Description
fClass function The class that is implementing the interface.
fInterface function The interface that the class must implement.

(static) isImplementorOf(oInstance, fClass) → {boolean}

Checks that an object instance implements all the public functions of the class (i.e. a duck-typing check). NB: does not check the entire prototype chain.
Parameters:
Name Type Description
oInstance Object An object instance that we are checking.
fClass function The class or interface we are checking against.
Throws:
Error if fClass is not a function.
Returns:
true if the instance is an instance of the class constructed by the function.
Type
boolean

(static) unsupported(sClassName, sMethodName)

Invoked by API methods that are no longer supported.
Parameters:
Name Type Description
sClassName String The name of the class that is no longer supported or the class that the unsupported method belongs to.
sMethodName String The name of the method that is no longer supported (Optional: not needed for constructors).