Thursday, June 28th, 2007
Cerny.js – Method call interception, Schemas, Type checking and more
Robert Cerny has created a JavaScript library in his own image Cerny.js.
The library has an entire slew of things:
- method call interception,
- type checking for arguments and return values on function calls,
- programming by contract,
- logging,
- validation of an object against a schema,
- dictionaries,
- pretty printing JSON in text or HTML,
- dependency management,
- easy configuration and
- good documentation.
One of the more out there ideas is for putting design by contract into your JavaScript world via something like this:
- var NewMath = {};
- (function() {
- // Shorten some names
- var check = CERNY.check;
- var pre = CERNY.pre;
- var method = CERNY.method;
- // The new division
- function divide(a,b) {
- return a / b;
- }
- // For contracts to be enforced, it is necessary
- // that a function is subject to interception. Therefore
- // CERNY.method must be used.
- method(NewMath, "divide", divide);
- // The precondition for a division
- pre(divide, function(a,b) {
- check(b !== 0, "b may not be 0");
- });
- })();
A lot to check out here.





3 rating from 25 votes
Is it friday already?
Nope. Next!
This has actually been out for a while. Given the dynamic nature of JS though, it seems like some things should be a little more automatic and less verbose. That said there are a few interesting ideas in there.
This is actually very interesting. Although all these ideas are not new, having them in one library is a good academic exercise.
perhaps good with java based javascript engine “Mozilla Rhino” :)
using java 6.0 Script engine.