JavaScript for Java developers

JavaScript for Java developers

Most Java developers stick up their nose if it comes to JavaScript. Today I would like to present you a way of dealing with JavaScript that is less alienating than learning prototype based inheritance and all the caveats about this.

How does a JavaScript with class based inheritance, types, generics and modules sound?

Let me introduce TypeScript to you. TypeScript syntax is a superset of Ecmascript 5 (ES5), and resembles in many areas the syntax of the draft Ecmascript 6. Being a superset of JavaScript has the great advantage that every normal JavaScript program is also a valid TypeScript program, which makes integration with everything out there much easier. Have a look at inheritance with TypeScript for example:

The example shows the use of classes, types and inheritance and is much more readable for me than the direct implementation in JavaScript. Convince yourself by having a look at the TypeScript Playground. BTW, our former Eclipse colleague Erich Gamma is in charge of the TypeScript playground. The playground has also a couple of nice editing features ...

To be executed in a JavaScript environment TypeScript has to be compiled into JavaScript. A node.js module made that really easy for me. With EcmaScript 6 (scheduled to arrive in December 2014) JavaScript is going to make another push into the Java and C# developer community. TypeScript is a nice way to get a sneak preview.

TypeScript has been created by Microsoft, it is Open Source, Apache licensed and its code is living at GitHub.