CERNY
This is the file that provides the core functionality of the Cerny.js library: interception, type checking, logging, dependency declaration, configuration and dictionaries.
To use the Cerny.js library this file must be included in your page. The configuration file (a copy of cerny.conf.js) must be included beforehand.
Some conventions used:
- If a current function or member is overwritten in a script, e.g. 'insertBefore', but will be referred to later, the new name of the member is composed of an underscore followed by the old name, e.g. '_insertBefore'.
- If a simple name is not possible due to keyword restrictions, the name is proceeded by an underscore, e.g. '_delete'.
- If a function takes arbitrarily many arguments, the documentation for these parameters must be called 'arguments'.
- If the documentation for a function does not specify a return value, the function returns undefined.
Uses
Used by
Functions
ContractViolation
Constructor for a contract violation.
Dictionary
Dictionary maker.
A dictionary is a mapping from terms to definitions. Definitions may contain nested terms. The process of evaluating a term is done by
lookup
.
Logger
Create a logger. For every category there exists exactly one logger.
name
check
Check whether expr evaluates to true. If not throw a
CERNY.ContractViolation
. Only to be used in preconditions, postconditions and invariants.
clone
Clone an object. This method is at the moment very limited in its capabilities.
dump
Dump a value for logging purposes. Returns the value of the variable followed by its type in braces. If the variable is a string, the value is enclosed by a single quote.
empty
The empty function.
*/
getResource
Get a resource.
identity
Returns the argument.
intercept
Instrument methods of an object for interception. Can be called multiple times with the same effect, only depending on
CERNY.Configuration.Interception.active
or the passed interceptors.
This function does not work on the
window
object in IE.
If one overrides methods of an existing object, where interception was already installed with this function and use this function again to intercept the method, the old method will be installed and a information will be logged. This is unfortunate, but is necessary so that interception always has the same effect. Workaround: Use
CERNY.method
to attach the methods (best to both, but definitely when overriding) instead.
isPresent
Check whether an expression is present during runtime.
false
, if the string does not reference anything or the string references
undefined
joinFunctions
Join functions into one function. The new function returns the return value of the last function.
load
Load a script. This function is called in
require
. It has different implementations in various environments (browser, Rhino [RHI]). The default runtime enviornment is the browser.
lookup
Lookup a term in this dictionary.
undefined
if the term is unknown
method
Attach a function as a method to an object. This allows to create arbitrarliy many functions around the actual function. It aims for separation of concerns. The interceptors are wrapped around the function starting with the last one. This allows a "natural order", when filling the array regarding dependency. So more basic interceptors (e.g.
LogIndenter
) are pushed first.
namespace
Create a namespace in
CERNY
. This function is inspired by the Yahoo! UI Library [YUI].
CERNY
object
Prototypal inheritance [DCP]. This alogorithm was developed by Douglas Crockford.
post
Specify the conditions that must be met in order to decide whether a function call was a success.
Postcondition is a function which is a sequence of calls to
CERNY.check
.
this
has the same meaning as in the function called.
Postcondition is passed the following parameters:
- the return value,
- the old version of the object the call is made on, and then
- the arguments of the call.
pre
Specify the conditions that must be met in order to decide whether a call to func can succeed. These conditions are collected in one function which is called the precondition. The precondition supports the author of a function in communicating the intent of the function to the consumer.
Precondition is a function which is a sequence of calls to
CERNY.check
.
Precondition is passed the arguments of the call and
this
has the same meaning as in the function called.
require
Check for the presence of expressions. Loads an expression by looking it up in the catalog.
signature
Specify the signature of a function. The types can be specified either by a string (
"boolean"
,
"string"
,
"number"
,
"object"
,
"function"
,
"undefined"
,
"null"
,
"any"
) or by a function, against which the actual value will be tested against with instanceof.
In the future it should be possible to specify an object as a type and the prototype chain is inspected for that object. Even more in the future it Cerny schemas could be used.

