My JavaScript book is out! Don't miss the opportunity to upgrade your beginner or average dev skills.

Wednesday, May 23, 2007

JavaStrict Act II - AS2.0 like Strict Type with JavaScript

I've just updated my JavaStrict public, static, function.

It has been successfully tested with different cases and now it behaviour is like ActionScript 2.0

With this function, and dedicated Strict shortcut one, You can:


  • define a return type, using a specific constructor or Void, if function mustn't return any kind of variable (null too)

  • define one or more argument constructor, using specified constructor or Void if function mustn't accept any kind of parameter (null too)

  • use a generic Object constructor, as returned or accepted instance if You don't know what kind of object function, r method, will accpet or return



You can use Object for DOM elements too, expecially with Internet Explorer (6 or lower) where DOM Elements are typeof "object" but aren't instances of Object.

Object is the super incoming or outgoing value type, it can be null or every kind of instance (obviously, Void is not Object, so You can't use Object to return Void values and vice-versa).

You can specify every other constructor type as returned value or accepted parameter, so You can write JavaScript using a special Stric Type automatic check to create easyly your own Web Apps, having an exception every time some parameter is wrong or isn't expected type.

I hope someone will be interested about this new way to write and debug JavaScript, quite strongly typed, not yet compiled style but, at least, more debuggable with every kind of library.

Performance ? Good enought, so have fun with JavaStrict :-)

(read here to view some example)

1 comment:

Anonymous said...

You write very well.