Comparison and inspiration
General sources of inspiration
- Mock object libraries and jQuery for the chaining syntax.
- More punctal credit is given in the code, with links
Available JavaScript type checking libraries
- cerny.js
- Pros
- Introduces lots of very useful tools for robust software development, like logging, programming by contract, and, of course, type checking
- Introduces the concept of "schema", which is similar, but not quite, to an interface
- Cons
- Pretty big if you only want type checking.
- No interface checking with function signatures, from what I could see.
- Inspiration for fSignatures
- Attaching a "_signature" object to the function comes from here.
- JS.class and this blog post on typechecking in JavaScript
- Pros
- Very simple.
- Interesting syntax.
- Has basic interface checking.
- Cons
- Must extend the Function object prototype.
- Wraps the function in two wrappers ("returns" and "expects")
- JS.interface does not check for function signatures.
- See "On type checking" section for some custom typeOf functions(), and John Resig's strict() argument checker.
Comparing fSignatures with available libraries
- Pros
- That's all it does: check types. It's standalone (no dependency, and doesn't come with a whole library) and you can use it on some functions and not on others (say functions where you would have done type checking anyway, in the function body).
- It brings an interface checking mechanism, really checking function signatures (as long as the objects' functions were declared using the syntax).
- Cons
- It's very new, so it's not field tested. You can help here :P (see Feedback)
- It's still not static type checking (ie. compile time), so it won't catch errors in calls until you run every call to your function. That's why it's useful to pair it with unit tests with good coverage. Furthermore, it won't help with IDEs (you won't get code completion as with static typing).
- By using wrapper functions, the call stack is made deeper.
ECMAScript 4 translators
- From the Mascara website: "Mascara is a tool that translates ECMAScript 4 to classic JavaScript, thereby enabling features like type-checking, classes and namespaces in JavaScript today."
- Jangaroo is a similar tool, written in Java.
- Pros
- Much more robust approach, and you get all the IDE-enabling features.
- It's static type checking: no need to run the code to detect a call error.
- Your code is ready for ECMAScript 4 compatible interpreters and browsers, when they arrive.
- Cons
- It's translated code, which may or may not suit you.
© Copyright 2008 François Savard