call_js

command
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 5, 2026 License: MIT Imports: 3 Imported by: 0

README

Calling JavaScript from Go

Load a script that defines functions, then drive it from Go: fetch a function global, call it with converted arguments, and read the result back.

go run ./examples/call_js

Expected output:

Hello, world!
stats: map[count:4 mean:5 total:20]

Key points:

  • vm.GetGlobal(name) fetches a value (e.g. a function) defined by the script.
  • vm.Call(fn, this, args...) invokes a callable JS value from Go. Pass gojs.Undefined for this unless calling a method.
  • Convert across the boundary with vm.FromGo (Go → JS) and vm.ToGo / vm.ToString (JS → Go).

Documentation

Overview

Example: calling JavaScript functions from Go.

The host loads a script that defines functions, then invokes them from Go with converted arguments and reads the results back.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL