Fantom

 

JavaScript

Overview

Fantom provides support for compiling to JavaScript and running in JavaScript VMs such as web browsers. Most of the sys API is available, however not all pods and APIs are accessible due to limitations of the JavaScript VM enviornment.

js facet

You must explictly mark types you intend to compile to JavaScript. You mark a type using the @js facet.

@js
class GonnaBeJs
{
  Void sayHi() { Win.cur.alert("Hello!") }
}

Compiling

To compile the types you've marked for JavaScript, add the @js facet to your pod definition.

// pod.fan
@podDepends=[...]
@js
pod myPod {...}

Natives

To compile JavaScript natives, add the source directories to your build script using the @podJsDirs facet.

// pod.fan
@podJsDirs =  [`js/`]

TODO: document how JavaScript peers operate