js

package
v0.0.0-...-230266e Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2015 License: BSD-2-Clause Imports: 0 Imported by: 0

Documentation

Overview

Package js provides functions for interacting with native JavaScript APIs. Calls to these functions are treated specially by GopherJS and translated directly to their corresponding JavaScript syntax.

Type conversions between Go types and JavaScript types are performed automatically according to the following table:

| Go type               | JavaScript type       | Conversions back to interface{} |
| --------------------- | --------------------- | ------------------------------- |
| bool                  | Boolean               | bool                            |
| integers and floats   | Number                | float64                         |
| string                | String                | string                          |
| []int8                | Int8Array             | []int8                          |
| []int16               | Int16Array            | []int16                         |
| []int32, []int        | Int32Array            | []int                           |
| []uint8               | Uint8Array            | []uint8                         |
| []uint16              | Uint16Array           | []uint16                        |
| []uint32, []uint      | Uint32Array           | []uint                          |
| []float32             | Float32Array          | []float32                       |
| []float64             | Float64Array          | []float64                       |
| all other slices      | Array                 | []interface{}                   |
| arrays                | see slice type        | see slice type                  |
| functions             | Function              | func(...interface{}) *js.object |
| time.Time             | Date                  | time.Time                       |
| -                     | instanceof Node       | *js.object                      |
| maps, structs         | instanceof Object     | map[string]interface{}          |

Additionally, for a struct containing a *js.object field, only the content of the field will be passed to JavaScript and vice versa.

Index

Constants

This section is empty.

Variables

View Source
var Arguments []*Object

Arguments gives the value of JavaScript's "arguments" keyword. It can be used when passing Go functions to JavaScript as callbacks.

Functions

func Debugger

func Debugger()

Debugger gets compiled to JavaScript's "debugger;" statement.

func Keys

func Keys(o *Object) []string

Keys returns the keys of the given JavaScript object.

Types

type Error

type Error struct {
	*Object
}

Error encapsulates JavaScript errors. Those are turned into a Go panic and may be rescued, giving an *Error that holds the JavaScript error object.

func (*Error) Error

func (err *Error) Error() string

Error returns the message of the encapsulated JavaScript error object.

func (*Error) Stack

func (err *Error) Stack() string

Stack returns the stack property of the encapsulated JavaScript error object.

type M

type M map[string]interface{}

M is a simple map type. It is intended as a shorthand for JavaScript objects (before conversion).

type Object

type Object struct {
	// contains filtered or unexported fields
}

Object is a container for a native JavaScript object. Calls to its methods are treated specially by GopherJS and translated directly to their JavaScript syntax. A nil pointer to Object is equal to JavaScript's "null". Object can not be used as a map key.

var Global *Object

Global gives JavaScript's global object ("window" for browsers and "GLOBAL" for Node.js).

var Module *Object

Module gives the value of the "module" variable set by Node.js. Hint: Set a module export with 'js.Module.Get("exports").Set("exportName", ...)'.

var This *Object

This gives the value of JavaScript's "this" keyword. It can be used when passing Go functions to JavaScript as callbacks.

var Undefined *Object

Undefined gives the JavaScript value "undefined".

func InternalObject

func InternalObject(i interface{}) *Object

InternalObject returns the internal JavaScript object that represents i. Not intended for public use.

func MakeWrapper

func MakeWrapper(i interface{}) *Object

MakeWrapper creates a JavaScript object which has wrappers for the exported methods of i. This can be used to provide getter and setter methods for Go fields to JavaScript.

func NewArrayBuffer

func NewArrayBuffer(b []byte) *Object

NewArrayBuffer creates a JavaScript ArrayBuffer from a byte slice.

func (*Object) Bool

func (o *Object) Bool() bool

Bool returns the object converted to bool according to JavaScript type conversions.

func (*Object) Call

func (o *Object) Call(name string, args ...interface{}) *Object

Call calls the object's method with the given name.

func (*Object) Delete

func (o *Object) Delete(key string)

Delete removes the object's property with the given key.

func (*Object) Float

func (o *Object) Float() float64

Float returns the object converted to float64 according to JavaScript type conversions (parseFloat).

func (*Object) Get

func (o *Object) Get(key string) *Object

Get returns the object's property with the given key.

func (*Object) Index

func (o *Object) Index(i int) *Object

Index returns the i'th element of an array.

func (*Object) Int

func (o *Object) Int() int

Int returns the object converted to int according to JavaScript type conversions (parseInt).

func (*Object) Int64

func (o *Object) Int64() int64

Int64 returns the object converted to int64 according to JavaScript type conversions (parseInt).

func (*Object) Interface

func (o *Object) Interface() interface{}

Interface returns the object converted to interface{}. See GopherJS' README for details.

func (*Object) Invoke

func (o *Object) Invoke(args ...interface{}) *Object

Invoke calls the object itself. This will fail if it is not a function.

func (*Object) Length

func (o *Object) Length() int

Length returns the object's "length" property, converted to int.

func (*Object) New

func (o *Object) New(args ...interface{}) *Object

New creates a new instance of this type object. This will fail if it not a function (constructor).

func (*Object) Set

func (o *Object) Set(key string, value interface{})

Set assigns the value to the object's property with the given key.

func (*Object) SetIndex

func (o *Object) SetIndex(i int, value interface{})

SetIndex sets the i'th element of an array.

func (*Object) String

func (o *Object) String() string

String returns the object converted to string according to JavaScript type conversions.

func (*Object) Uint64

func (o *Object) Uint64() uint64

Uint64 returns the object converted to uint64 according to JavaScript type conversions (parseInt).

func (*Object) Unsafe

func (o *Object) Unsafe() uintptr

Unsafe returns the object as an uintptr, which can be converted via unsafe.Pointer. Not intended for public use.

type S

type S []interface{}

S is a simple slice type. It is intended as a shorthand for JavaScript arrays (before conversion).

Jump to

Keyboard shortcuts

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