Friday, March 25th, 2005

Declarative JavaScript programming

Category: JavaScript

Do you want to go annotation crazy in the JavaScript world? Anders Norås has created annotation support in JavaScript.

He follows the XDoclet-style approach, in that annotations are tacked on via comments:

Calculator.square=function(num) {
 *@Modifiers(modifiers=Modifier.static|Modifier.public) *@Returns(type=�number�,description=�The square of the given number�)
 return num*num;

and then you can get at the annotation data via:

var version=Reflection.getNamedAnnotation(Calculator.square);
alert(“Major: “+version.major+'\n'+
      "Minor: “+version.minor+'\n'+

Maybe the next ECMAScript will have true annotation support as part of the language? Does it matter as much in JavaScript?

Posted by Dion Almaer at 1:09 pm

2.3 rating from 7 votes


Comments feed

Doesn’t work on Mozilla

Comment by td — January 22, 2006

Doesn’t work for me either

Comment by jarvez — December 14, 2009

Leave a comment

You must be logged in to post a comment.