Thursday, June 28th, 2007

Cerny.js – Method call interception, Schemas, Type checking and more

Category: JavaScript, Library

<>p>Robert Cerny has created a JavaScript library in his own image Cerny.js.

The library has an entire slew of things:

One of the more out there ideas is for putting design by contract into your JavaScript world via something like this:

javascript
< view plain text >
  1. var NewMath = {};
  2.  
  3. (function() {
  4.  
  5.     // Shorten some names
  6.     var check = CERNY.check;
  7.     var pre = CERNY.pre;
  8.     var method = CERNY.method;
  9.  
  10.     // The new division
  11.     function divide(a,b) {
  12.       return a / b;
  13.     }
  14.  
  15.     // For contracts to be enforced, it is necessary
  16.     // that a function is subject to interception. Therefore
  17.     // CERNY.method must be used.
  18.     method(NewMath, "divide", divide);
  19.     // The precondition for a division
  20.     pre(divide, function(a,b) {
  21.        check(b !== 0, "b may not be 0");
  22.     });
  23. })();

A lot to check out here.

Related Content:

Posted by Dion Almaer at 8:12 am
5 Comments

+++--
3 rating from 25 votes

5 Comments »

Comments feed TrackBack URI

Is it friday already?

Comment by Sergej — June 28, 2007

Nope. Next!

Comment by Dan — June 28, 2007

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.

Comment by Ryan Johnson — June 28, 2007

This is actually very interesting. Although all these ideas are not new, having them in one library is a good academic exercise.

Comment by Ahmed — June 28, 2007

perhaps good with java based javascript engine “Mozilla Rhino” :)
using java 6.0 Script engine.

Comment by nhm tanveer hossain khan (hasan) — June 29, 2007

Leave a comment

You must be logged in to post a comment.