|
@@ -3,7 +3,7 @@ goja
|
|
|
|
|
|
ECMAScript 5.1(+) implementation in Go.
|
|
ECMAScript 5.1(+) implementation in Go.
|
|
|
|
|
|
-[](https://godoc.org/github.com/dop251/goja)
|
|
|
|
|
|
+[](https://pkg.go.dev/github.com/dop251/goja)
|
|
|
|
|
|
Goja is an implementation of ECMAScript 5.1 in pure Go with emphasis on standard compliance and
|
|
Goja is an implementation of ECMAScript 5.1 in pure Go with emphasis on standard compliance and
|
|
performance.
|
|
performance.
|
|
@@ -153,13 +153,13 @@ if num := v.Export().(int64); num != 4 {
|
|
|
|
|
|
Passing Values to JS
|
|
Passing Values to JS
|
|
--------------------
|
|
--------------------
|
|
-Any Go value can be passed to JS using Runtime.ToValue() method. See the method's [documentation](https://godoc.org/github.com/dop251/goja#Runtime.ToValue) for more details.
|
|
|
|
|
|
+Any Go value can be passed to JS using Runtime.ToValue() method. See the method's [documentation](https://pkg.go.dev/github.com/dop251/goja#Runtime.ToValue) for more details.
|
|
|
|
|
|
Exporting Values from JS
|
|
Exporting Values from JS
|
|
------------------------
|
|
------------------------
|
|
A JS value can be exported into its default Go representation using Value.Export() method.
|
|
A JS value can be exported into its default Go representation using Value.Export() method.
|
|
|
|
|
|
-Alternatively it can be exported into a specific Go variable using [Runtime.ExportTo()](https://godoc.org/github.com/dop251/goja#Runtime.ExportTo) method.
|
|
|
|
|
|
+Alternatively it can be exported into a specific Go variable using [Runtime.ExportTo()](https://pkg.go.dev/github.com/dop251/goja#Runtime.ExportTo) method.
|
|
|
|
|
|
Within a single export operation the same Object will be represented by the same Go value (either the same map, slice or
|
|
Within a single export operation the same Object will be represented by the same Go value (either the same map, slice or
|
|
a pointer to the same struct). This includes circular objects and makes it possible to export them.
|
|
a pointer to the same struct). This includes circular objects and makes it possible to export them.
|
|
@@ -168,7 +168,7 @@ Calling JS functions from Go
|
|
----------------------------
|
|
----------------------------
|
|
There are 2 approaches:
|
|
There are 2 approaches:
|
|
|
|
|
|
-- Using [AssertFunction()](https://godoc.org/github.com/dop251/goja#AssertFunction):
|
|
|
|
|
|
+- Using [AssertFunction()](https://pkg.go.dev/github.com/dop251/goja#AssertFunction):
|
|
```go
|
|
```go
|
|
vm := New()
|
|
vm := New()
|
|
_, err := vm.RunString(`
|
|
_, err := vm.RunString(`
|
|
@@ -191,7 +191,7 @@ if err != nil {
|
|
fmt.Println(res)
|
|
fmt.Println(res)
|
|
// Output: 42
|
|
// Output: 42
|
|
```
|
|
```
|
|
-- Using [Runtime.ExportTo()](https://godoc.org/github.com/dop251/goja#Runtime.ExportTo):
|
|
|
|
|
|
+- Using [Runtime.ExportTo()](https://pkg.go.dev/github.com/dop251/goja#Runtime.ExportTo):
|
|
```go
|
|
```go
|
|
const SCRIPT = `
|
|
const SCRIPT = `
|
|
function f(param) {
|
|
function f(param) {
|
|
@@ -222,7 +222,7 @@ Mapping struct field and method names
|
|
-------------------------------------
|
|
-------------------------------------
|
|
By default, the names are passed through as is which means they are capitalised. This does not match
|
|
By default, the names are passed through as is which means they are capitalised. This does not match
|
|
the standard JavaScript naming convention, so if you need to make your JS code look more natural or if you are
|
|
the standard JavaScript naming convention, so if you need to make your JS code look more natural or if you are
|
|
-dealing with a 3rd party library, you can use a [FieldNameMapper](https://godoc.org/github.com/dop251/goja#FieldNameMapper):
|
|
|
|
|
|
+dealing with a 3rd party library, you can use a [FieldNameMapper](https://pkg.go.dev/github.com/dop251/goja#FieldNameMapper):
|
|
|
|
|
|
```go
|
|
```go
|
|
vm := New()
|
|
vm := New()
|
|
@@ -236,14 +236,14 @@ fmt.Println(res.Export())
|
|
// Output: 42
|
|
// Output: 42
|
|
```
|
|
```
|
|
|
|
|
|
-There are two standard mappers: [TagFieldNameMapper](https://godoc.org/github.com/dop251/goja#TagFieldNameMapper) and
|
|
|
|
-[UncapFieldNameMapper](https://godoc.org/github.com/dop251/goja#UncapFieldNameMapper), or you can use your own implementation.
|
|
|
|
|
|
+There are two standard mappers: [TagFieldNameMapper](https://pkg.go.dev/github.com/dop251/goja#TagFieldNameMapper) and
|
|
|
|
+[UncapFieldNameMapper](https://pkg.go.dev/github.com/dop251/goja#UncapFieldNameMapper), or you can use your own implementation.
|
|
|
|
|
|
Native Constructors
|
|
Native Constructors
|
|
-------------------
|
|
-------------------
|
|
|
|
|
|
In order to implement a constructor function in Go use `func (goja.ConstructorCall) *goja.Object`.
|
|
In order to implement a constructor function in Go use `func (goja.ConstructorCall) *goja.Object`.
|
|
-See [Runtime.ToValue()](https://godoc.org/github.com/dop251/goja#Runtime.ToValue) documentation for more details.
|
|
|
|
|
|
+See [Runtime.ToValue()](https://pkg.go.dev/github.com/dop251/goja#Runtime.ToValue) documentation for more details.
|
|
|
|
|
|
Regular Expressions
|
|
Regular Expressions
|
|
-------------------
|
|
-------------------
|