This article is more than 1 year old

Improving JavaScript: Google throws AtScript into the mix

Better JavaScript ... even works with Microsoft's TypeScript

Google’s Miško Hevery, co-inventor of the popular AngularJS framework, has announced a new project to improve JavaScript by adding type annotations and other features.

Miško Hevery presents AtScript

Miško Hevery presents AtScript at ngEurope

The announcement came at the ng-europe Angular conference in Paris at the end of October 2014.

AtScript is the latest among numerous projects to fix up JavaScript’s deficiencies. Developers love JavaScript because it runs everywhere and performs well, thanks to fast engines like Apple’s Nitro and Google’s V8. That said, the absence of language features like types and classes make large, multi-developer JavaScript projects hard to maintain.

One solution is to write code in a different language that is compiled to JavaScript for deployment. Google’s Dart language is an example, with the twist that Dart can also be executed directly by a Dart VM (Virtual Machine) where this exists.

Google Web Toolkit is another one, which compiles Java to JavaScript. The downside of these options is that they replace JavaScript with another language, rather than making JavaScript itself better. This impairs interoperability with JavaScript libraries, and puts them at odds with official efforts to evolve JavaScript itself.

Microsoft’s TypeScript takes a different approach, being a superset of JavaScript that adds classes and strong typing but does not replace the language. TypeScript compiles to readable JavaScript, making debugging easier.

AtScript is more in tune with the TypeScript approach. It adds two features to JavaScript. The first is Annotations, which can be Type annotations, Field annotations, or Metadata annotations. Type annotations declare the type of a variable or argument. Field annotations let you specify the type and order of fields in a class. Metadata annotations attach metadata to the code, for example for use by frameworks.

The second feature is Introspection, which lets you query the annotations at runtime.

AtScript builds on EcmaScript 6 (ES6), which is the official next version of JavaScript, rather than EcmaScript 5 (ES5), the current version implemented in modern web browsers. ES6 adds classes and modules (a means of isolating and organising code), but not types. In order to deploy AtScript, it is compiled with the traceur compiler, which converts ES6 into ES5. There is also an option to compile to Dart.

The quick summary therefore is “AtScript = ES6 + Types + Annotations + Introspections”.

Is AtScript necessary, given that TypeScript does some of this already? Hevery says that AtScript is influenced by TypeScript (as well as Dart) but that TypeScript lacks runtime introspection and metadata annotations. However, you can use AtScript with TypeScript, so the two projects are not altogether in opposition. This could get messy though, since features like metadata have already been proposed for the next version of TypeScript.

Angular 2.0, the next version, is being rewritten from scratch in AtScript. This means it is an ES6 project.

“We're building AngularJS in ES6 now so you’ll have a framework that’s ready to take full advantage of ES6 as browsers add support,” says the team, though it will of course compile to ES5 code.

For more information on AtScript, see Hevery's keynote here. ®

More about


Send us news

Other stories you might like