Docs menu

Differences from Go

View as Markdown

Each comes from JavaScript, and a test pins each one.

One number type #

Go keeps int and float64 apart; JavaScript cannot. obol treats a safe integer as an int:

  • {{1e6}} prints 1000000, where Go prints 1e+06.
  • {{eq 1 1.0}} is true.
  • %f takes an integer, and %d takes 5.0.

Other numbers print as Go prints floats, so 1234567.5 shows as 1.2345675e+06. Reach for printf "%.2f".

Key order #

Go sorts map keys in range and when it prints a map. obol keeps the order of the object or Map. JavaScript puts integer keys of a plain object first, in ascending order, then the rest as added.

Strings #

len, index and slice count UTF-16 units, where Go counts bytes. They agree on ASCII. {{len "héllo"}} is 5 in obol and 6 in Go.

No complex numbers #

{{1+2i}} is a parse error.

Arguments #

Go checks the count and types of arguments to your functions. obol passes them through, as JavaScript does. Builtins still check theirs.

Depth #

Templates nest 250 calls deep, where Go allows 100,000.

Type names #

Errors and %T name JavaScript values with Go types: an array is []interface {}, and a plain object map[string]interface {}. A class instance goes by its class name.

html/template #

Go's contextual escaper is not part of obol. Escape with html, js and urlquery; see Functions.