<small id='tMd7X56KPr'></small> <noframes id='tpD6I'>

  • <tfoot id='9NdX14Y7'></tfoot>

      <legend id='wrLOQHy'><style id='QNbowFG'><dir id='LCEo'><q id='RPOY6j'></q></dir></style></legend>
      <i id='GFNpA25xcK'><tr id='HZcdLzg'><dt id='eNArKQzt7'><q id='gG4ena7X'><span id='yAFLezapb'><b id='VhDCXsYqdT'><form id='Z3O8AWziL7'><ins id='JEqTFx'></ins><ul id='6nC1BvfX'></ul><sub id='T0IR'></sub></form><legend id='KEavbtw'></legend><bdo id='DJ6gQphK'><pre id='4s0awUTHpb'><center id='iY6qbpP0'></center></pre></bdo></b><th id='SIOa8qWv'></th></span></q></dt></tr></i><div id='49tUNj5'><tfoot id='brWqoPd'></tfoot><dl id='9tloxWYaw'><fieldset id='rKe28ZIkX'></fieldset></dl></div>

          <bdo id='soN3yvw'></bdo><ul id='u4LZxnFah'></ul>

          1. <li id='1M7Sc'></li>
            登陆

            v8go - 从Go履行JavaScript

            admin 2019-12-22 275人围观 ,发现0个评论

            v8go

            从Go履行JavaScript

            V8依靠

            V8版别:7.6.303.31

            为了使其v8go可用作规范Go包,可认为Linux和OSX包括预构建的V8静态库。

            V8需求64位,因而无法在32位体系上运转。

            用法

            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", val)

            一个VM,许多状况

            vm, _ := v8go.NewIsolate() // creates a new JavaScript VM
            ctx1, _ := v8go.NewContext(vm) // new context within the VM
            ctx1.RunScript("const multiply = (a, b) => a * b", "math.js")

            ctx2, _ := v8go.NewContext(vm) // another context on the same VM
            if _, err := ctx2.RunScript("multiply(3, 4)", "main.js"); err != nil {
            // this will err陶慧or as multiply is not defined in this context
            }

            Javascript过错

            val, err := ctx.RunScript(src, filename)
            if err != nil {
            err = ev8go - 从Go履行JavaScriptrr.(v8go.JSError) // JavaScript errors will be returned as the JSError struct
            fmt.Println(err.Message) // the message of the exception thrown
            fmt.Println(err.Location) // the filename, line number and the column where the error occured
            fmt.Println(err.StackTrace) // the full stack trace of the error, if available

            fmt.Printf("javascript error: %v", err) // will format the standard error message
            fmt.Printf("javascript stack trace: %+v", err) // will format the full error stack trace
            }

            更多运用文档能够看官方材料

            开源地址:

            因为头条审阅网址比较严,避免他们误会是推行,所以我们能够自行查找下载

            也能够重视我的头条号后给我发送 `v8go`,会主动把下载地址发送给你(做了关键字主动回复)

            您知道哪些好用的小工具,欢迎谈论共享,一起v8go - 从Go履行JavaScript讨论学习

            更多更优质的资讯,请重视我,你v8go - 从Go履行JavaScript的支撑会鼓舞我不断共享更多更好的优质文章。

            请关注微信公众号
            微信二维码
            不容错过
            Powered By Z-BlogPHP