Type Checking Demo

This page demonstrates the type checking feature of Cerny.js. A signature is specified by means of CERNY.signature. The runtime type check is performed by an interceptor. Type errors will be logged to the console in the color red.

The following code fragment defines a simple date function DateUtils.isPastDate. Further down you can input a function call to this function and observe the detection of type violations.

// A simple DateUtils object var DateUtils = { logger: CERNY.Logger("DateUtils") }; DateUtils.isPastDate = function(date) { return date.getTime() < new Date().getTime(); } // Specify the signature CERNY.signature(DateUtils.isPastDate, "boolean", Date); // For the sake of the example the TypeChecker interceptor // has to be present -> Customized interceptors array. // Otherwise the TypeChecker is configured in cerny.conf.js. CERNY.intercept(DateUtils, [CERNY.Interceptors.LogIndenter, CERNY.Interceptors.Tracer, CERNY.Interceptors.TypeChecker]);

Input

Example 1 Example 2 Example 3

Console