Documentation ¶
Index ¶
- func FuncOf(fn func(this JSValue, args []JSValue) any) js.Func
- func TrySet(_param ...string) error
- type JSValue
- func (_v JSValue) Bool() bool
- func (_v JSValue) Call(m string, args ...any) JSValue
- func (_v JSValue) Check(propertyname string) (JSValue, error)
- func (_v JSValue) Delete(p string)
- func (_v JSValue) Equal(w JSValue) bool
- func (_v JSValue) Float() float64
- func (_v JSValue) Get(_pname string) JSValue
- func (_v JSValue) GetBool(_pname string) bool
- func (_v JSValue) GetFloat(_pname string) float64
- func (_v JSValue) GetInt(_pname string) int
- func (_v JSValue) GetObject(_pname string) JSValue
- func (v JSValue) GetString(pname string) string
- func (_v JSValue) Index(i int) JSValue
- func (_v JSValue) InstanceOf(t JSValue) bool
- func (_v JSValue) Int() int
- func (_v JSValue) Invoke(args ...any) JSValue
- func (_v JSValue) IsDefined() bool
- func (_v JSValue) IsObject() bool
- func (_v JSValue) Length() int
- func (_v JSValue) New(args ...any) JSValue
- func (_v JSValue) Set(p string, x any)
- func (_v JSValue) String() string
- func (_v JSValue) Then(f func(JSValue))
- func (_v JSValue) Truthy() bool
- func (_v JSValue) Type() TYPE
- func (_v JSValue) Value() JSValue
- func (_v *JSValue) Wrap(_jsvp JSValueProvider)
- type JSValueProvider
- type JSValueWrapper
- type TYPE
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FuncOf ¶
FuncOf returns a wrapped function.
Invoking the JavaScript function will synchronously call the Go function fn with the value of JavaScript's "this" keyword and the arguments of the invocation. The return value of the invocation is the result of the Go function mapped back to JavaScript according to ValueOf.
A wrapped function triggered during a call from Go to JavaScript gets executed on the same goroutine. A wrapped function triggered by JavaScript's event loop gets executed on an extra goroutine. Blocking operations in the wrapped function will block the event loop. As a consequence, if one wrapped function blocks, other wrapped funcs will not be processed. A blocking function should therefore explicitly start a new goroutine.
Func.Release must be called to free up resources when the function will not be used any more.
Types ¶
type JSValue ¶
type JSValue struct {
// contains filtered or unexported fields
}
JSValue represents a JavaScript value. On wasm architecture, it wraps the JSValue from https://golang.org/pkg/syscall/js/ package.
func Global ¶
func Global() JSValue
Global returns the JavaScript global object, usually "window" or "global".
func ValueOf ¶
ValueOf returns x as a JavaScript value:
| Go | JavaScript | | ---------------------- | ---------------------- | | js.Value | [its value] | | js.Func | function | | nil | null | | bool | boolean | | integers and floats | number | | string | string | | []interface{} | new array | | map[string]interface{} | new object |
Panics if x is not one of the expected types.
func (JSValue) Bool ¶
Bool returns the value v as a bool. It panics if v is not a JavaScript boolean.
func (JSValue) Call ¶
Call does a JavaScript call to the method m of value v with the given arguments. It panics if v has no method m. Returns js.null if _v is undefined. The arguments get mapped to JavaScript values according to the ValueOf function.
func (JSValue) Check ¶
Check is like Get but returns an error without printing a warning in case of an error
func (JSValue) Delete ¶
Delete deletes the JavaScript property p of value v. It panics if v is not a JavaScript object.
func (JSValue) Equal ¶
Equal reports whether v and w are equal according to JavaScript's === operator.
func (JSValue) Float ¶
Float returns the value v as a float64. It panics if v is not a JavaScript number.
func (JSValue) Get ¶
Get returns the JavaScript property p of value v. Returns js.null if _v is undefined or unable to get p. Print a warning in these cases.
func (JSValue) GetObject ¶
GetObject returns the value of _v ensuring it's of type Object, otherwise returns null
func (JSValue) Index ¶
Index returns JavaScript index i of value v. It panics if v is not a JavaScript object. Returns js.null if _v is undefined and print a warning.
func (JSValue) InstanceOf ¶
func (JSValue) Int ¶
Int returns the value v truncated to an int. It panics if v is not a JavaScript number.
func (JSValue) Length ¶
Length returns the JavaScript property "length" of v. It panics if v is not a JavaScript object. Returns js.null if _v is undefined and print a warning.
func (JSValue) New ¶
New uses JavaScript's "new" operator with value v as constructor and the given arguments. It panics if v is not a JavaScript function. The arguments get mapped to JavaScript values according to the ValueOf function.
func (JSValue) Set ¶
Set sets the JavaScript property p of value v to ValueOf(x). It panics if v is not a JavaScript object. Returns js.null if _v is undefined and print a warning.
func (JSValue) String ¶
String returns the value v as a string. String is a special case because of Go's String method convention. Unlike the other getters, it does not panic if v's Type is not TypeString. Instead, it returns a string of the form "<T>" or "<T: V>" where T is v's type and V is a string representation of v's value.
func (JSValue) Truthy ¶
Truthy returns the JavaScript "truthiness" of the value v. In JavaScript, false, 0, "", null, undefined, and NaN are "falsy", and everything else is "truthy". See https://developer.mozilla.org/en-US/docs/Glossary/Truthy.
func (JSValue) Type ¶
Type returns the JavaScript type of the value v. It is similar to JavaScript's typeof operator, except that it returns TypeNull instead of TypeObject for null.
func (*JSValue) Wrap ¶
func (_v *JSValue) Wrap(_jsvp JSValueProvider)
type JSValueProvider ¶
type JSValueProvider interface {
Value() JSValue
}
JSValueProvider is implemented by types that are backed by a JavaScript value.
type JSValueWrapper ¶
type JSValueWrapper interface {
Wrap(JSValueProvider)
}
type TYPE ¶
type TYPE int
TYPE represents the JavaScript type of a Value.
const ( TYPE_UNDEFINED TYPE = TYPE(js.TypeUndefined) TYPE_NULL TYPE = TYPE(js.TypeNull) TYPE_BOOLEAN TYPE = TYPE(js.TypeBoolean) TYPE_NUMBER TYPE = TYPE(js.TypeNumber) TYPE_STRING TYPE = TYPE(js.TypeString) TYPE_SYMBOL TYPE = TYPE(js.TypeSymbol) TYPE_OBJECT TYPE = TYPE(js.TypeObject) TYPE_FUNCTION TYPE = TYPE(js.TypeFunction) )
Constants that enumerates the JavaScript types.