Friday, March 25th, 2005
Declarative JavaScript programming
<p>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) {
/**
*@Version(“1.0.0�)
*@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?
Related Content:











Doesn’t work on Mozilla
Doesn’t work for me either