v8go:从Go执行JavaScript

时间:2024-02-24 08:06:23
【文件属性】:

文件名称:v8go:从Go执行JavaScript

文件大小:19.38MB

文件格式:ZIP

更新时间:2024-02-24 08:06:23

javascript go golang v8 v8-javascript-engine

从Go执行JavaScript 用法 import "rogchap.com/v8go" 运行脚本 ctx , _ := v8go . NewContext ( nil ) // creates a new V8 context with a new Isolate aka VM ctx . RunScript ( "const add = (a, b) => a + b" , "math.js" ) // executes a script on the global context ctx . RunScript ( "const result = add(3, 4)" , "main.js" ) // any functions previously added to the context can be called val , _ := ctx . RunScript ( "result" , "value.js" ) // return a value in JavaScript back to Go fmt . Printf ( "addition result: %s"


网友评论