Tuesday, February 3rd, 2009

Joose 2.0 released

Category: JavaScript, Library


  1. Class("Point", {
  2.     has: {
  3.         x: {is: "ro"},
  4.         y: {is: "rw"},
  5.     },
  6.     methods: {
  7.         clear: function () {
  8.             this.x = 0;
  9.             this.setY(0);
  10.         }
  11.     }
  12. })

Malte Ubl and the Joose folk are always pushing the boundaries on munging JavaScript to their whim. They have a new 2.0 release, titled “death of parseInt” which has the new features of:

Major News

Support for types and type coercions in attributes and method signatures: JavaScript purists might find this a little disturbing but Joose now supports type declaration. Joose types, however, are quite the opposite of static types, because they try very hard to convert everything you throw at them to the type you want. parseInt is dead!
Here is the documentation.


  • Builtin support for turning a class into a singleton

    1. Class("MySingleton", {
    2.         does: [Joose.Singleton],
    4.         has: {
    5.             test: {
    6.                 init: function () { return [] }
    7.             }
    8.         }
    9.     })
    11.     var single = MySingleton.getInstance();
  • Support for Rhino without need for special configuration
  • The default namespace for types (which used to be experimental) is now Joose.Type
  • Experimental support for multi method dispatch. Examples.
  • Made integrating Joose with other class builders easier.
  • Fixed type checks for arrays (thanks Silvan).
  • Fixed an issue when overriding getters and setters defined in a super class.
  • Improved error messages when defining properties of classes, etc. but passing null to the property (happens easily when you have a typo in the last part of a name spaced identifier).

For those that haven’t seen us post on it before, what is Joose?

Joose is a self-hosting meta object system for JavaScript with support for classes, inheritance, mixins, traits, method modifiers and more.

Joose makes object-oriented programming with JavaScript easy, declarative and very productive. The Joose meta-object system is multi-paradigm. It supports class-based and prototype-based programming styles as well as class-based inheritance and role-based extention.

The Joose framework has been successfully used in multiple production systems for twelve months now and has been proven to be very stable. Joose is being tested using an automated unit-test suite that is being run in all major browsers (Firefox, IE, Safari, Opera and Chrome).

To get started with Joose we recommend to read the getting started guide.

Posted by Dion Almaer at 8:56 am

3.8 rating from 29 votes


Comments feed TrackBack URI

It wasn’t clear to me on a couple things:
First, why two forms of inheritance? How do these two forms interact with each other without leaking? Am I supposed to stay in the cage of one and not use the other?
Are Class “types” I declare interchangeable with native “types”? If so, how does the coercion work?
Do you have any other examples of the comparisons between hand written JavaScript and Joose? Looking at this page doesn’t seem to me to be very representative. I’ve never seen anyone write a Point class like that in JS plus the comparison doesn’t even contain the same interface.

Comment by TNO — February 3, 2009

Two forms of inheritance? “isa” does inheritance while “does” does trait-like or role-like extention which is a concept similar but more powerful to mixins. See http://www.iam.unibe.ch/~scg/Research/Traits/
Types are not classes. Types are basically things (objects of class Joose.TypeConstraint) that validate a piece of data. Joose.Type.Int for example coerces strings to int by calling parseInt.
With respect to the examples: They do implement the same interface (is: “rw”) tells the attribute meta class to generate accessor methods for the attributes. Of course, this is a dramatization :) For some more example code, we recommend looking at the examples. E.g:

Comment by Malde — February 3, 2009

I wonder why every property should have get/set … we are not in “Java world”, fortunately, so I miss cons about this old style javaScript:
function Point(x,y){this.x=x||0;this.y=y||0};
… also … where is the constructor with its arguments? Is it possible to have Python style initializzation?
function A(){return this instanceof arguments.callee ? this : new arguments.callee};
A() instanceof A;

I like the project “case study” but I still do not get what it could be used for (I mean, don’t you like JavaScript? Its syntax is so clear and simple, so why over-engineer it?)

Comment by WebReflection — February 3, 2009

We are using the getters and setters, so that they can be decorated with method modifiers (think aspects) which can be very handy when you, e.g. want to draw stuff when attributes change, etc.
Every class has a default initializer that accepts as properties object which is used for attribute values (using the setters for assignment). You may override the method initialize which receives the arguments to the constructor to provide custom initialization. You can also apply method modifiers to the initialize method to do special stuff at init time while keeping the default / super class behavior. For achieving python style behavior you would have to implement your own meta class with a custom constructor method for your objects.
We actually like JavaScript very much and Joose tries to bring all those features to JS while keeping the spirit alive :) What we dont like is writing boilerplate code for things like calling super class methods, etc. Joose is probably not for everyone, but it makes us happy.

Comment by Malde — February 3, 2009

What I’d like to see is an example of it working well with jQuery. Just out of curiosity.

Comment by Nosredna — February 3, 2009

Our usual approach is to have object representing widgets on the screen which have an instance variabel called $ that refers to the jQuery objects that represents the widget on screen.
You can then add e.g. roles to add functionality to particular widgets. See http://joose-js.blogspot.com/2009/01/aspect-oriented-programming-with.html for some example code (That i using jQuery, but not really focusing on the topic).
Our example app blok for collaborative editing of diagrams and ui prototypes is making extensive use of this pattern. It’s source code is in the examples directory. http://blok.appspot.com/

Comment by Malde — February 4, 2009

Leave a comment

You must be logged in to post a comment.