Since JavaScript is the only programming language guaranteed to work on a web browser, it is a necessary element for those who develop web. However, many people still do not want to write.
So I will introduce jsweet that I would like to use for Java programmers this time. Java is JavaScript to compile.
How to use jsweet
An example. The original Java has this form.
package quickstart;
import static def.dom.Globals.alert;
import static def.jquery.Globals.$;
import java.util.ArrayList;
import java.util.List;
import def.js.Array;
/**
* This class is used within the webapp/index.html file.
*/
public class QuickStart {
public static void main(String[] args) {
// you can use regular Java API
List<string> l = new ArrayList<>();
l.add("Hello");
l.add("world");
// and you can also use regular JavaScript APIs
Array</string><string> a = new Array<>();
a.push("Hello", "world");
// use of jQuery with the jQuery candy
$("#target").text(l.toString());
// use of the JavaScript DOM API
alert(a.toString());
}
}
It is after conversion.
/* Generated from Java with JSweet 2.0.0 - http://www.jsweet.org */
var quickstart;
(function (quickstart) {
/**
* This class is used within the webapp/index.html file.
* @class
*/
var QuickStart = (function () {
function QuickStart() {
}
QuickStart.main = function (args) {
var l = ([]);
/* add */ (l.push("Hello") > 0);
/* add */ (l.push("world") > 0);
var a = (new Array());
a.push("Hello", "world");
$("#target").text(/* toString */ ('[' + l.join(', ') + ']'));
alert(a.toString());
};
return QuickStart;
}());
quickstart.QuickStart = QuickStart;
QuickStart["__class"] = "quickstart.QuickStart";
})(quickstart || (quickstart = {}));
quickstart.QuickStart.main(null);
Using this library will make the code amazing, but jsweet is proportionally easy to read. Function is returned for each namespace, so is not it easy to understand the converted code? You can also use jQuery in combination.
jsweet is Java open source software (GPL v3).
No comments:
Post a Comment