You opt-in to using asm.js by including the
"use asm"; string at the top of your file or individual function, just like you opt into strict mode with
+a would annotate the a variable as a double.
a|0 would annotate it as an integer.
If all of this sounds a bit tedious to write, I would agree, although it’s far from the worst syntax we could have. However, it isn’t really targeted at human authors, but compilers like Emscripten, Mandreel, LLJS, or perhaps even TypeScript which can generate the cleverly backwards compatible but not terribly clear type annotations for you from another existing language like C, or a new language like LLJS or TypeScript. Emscripten already generates valid asm.js output and was one of the main impetuses behind the the project, and Firefox will be landing their asm.js optimizing compiler in the near future. The benchmarks look very impressive indeed.
Be sure to check out the asm.js spec, David Herman’s prototype asm.js validator on Github (written in JS!), and Emscripten developer Alon Zakai’s presentation about Emscripten, asm.js and the future. I’m looking forward to watching all of these projects as they develop!