Chapter 14. Using AssemblyScript and WebAssembly
There’s something strange going on tonight There’s something going on that’s not quite right Joey’s nervous and the lights are bright There’s something going on that’s not quite right
Wire, “Strange”
It is getting harder for me to make cultural references that the general populace gets. There is a good chance that many of the people reading this book will not recognize this song, but it is still important to reference the classics. For those of you cultured enough1 to recognize the aforementioned song as an R.E.M. song on the Document album,2 you may be surprised to learn it is a cover. The original was done by the band Wire. If you listen to the original, your reaction to this might be that something strange is going on, just like the song says. It is both familiar and not at the same time.
In this chapter, I am going to introduce a language called AssemblyScript that might prompt the same reaction. It is a Binaryen-based compiler that turns a subset of TypeScript into WebAssembly. It is obviously similar to TypeScript (which is, in turn, similar to JavaScript), but upon closer inspection, something strange is going on here, too. Still, it fits a different use case for WebAssembly and shows you how versatile this platform can be.
TypeScript is a popular superset of JavaScript that transpiles3 to regular JavaScript so that it will run anywhere JavaScript will. Its main purpose is to express your intent using a strongly typed ...