func (v Value) SetIndex(i int, val interface{}) {
	v.Ref.SetIndex(i, valueOf(val))
}
SetIndex sets the JavaScript index i of value v to ValueOf(x).
package js
import (
	"strings"
	"sync"
)
var (
	object = global.Get("Object")
	array  = global.Get("Array")
)
var (
	mu      sync.RWMutex
	classes = make(map[string]Value)
)
type Obj = map[string]interface{}
type Arr = []interface{}
func Get(name string, path ...string) Value {
	return Value{global}.Get(name, path...)
}
func Set(name string, v interface{}) {
	Value{global}.Set(name, v)
}
func Call(name string, args ...interface{}) Value {
	return Value{global}.Call(name, args...)
}
func Class(class string, path ...string) Value {
	switch class {
	case "Object":
		return Value{object}
	case "Array":
		return Value{array}
	}
	key := class
	if len(path) != 0 {
		key += "." + strings.Join(path, ".")
	}
	mu.RLock()
	v := classes[key]
	mu.RUnlock()
	if v.isZero() {
		v = Get(class, path...)
		mu.Lock()
		classes[key] = v
		mu.Unlock()
	}
	return v
}
func New(class string, args ...interface{}) Value {
	v := Class(class)
	return v.New(args...)
}
func NewError(e Wrapper) error {
	return Error{Value: e.JSValue()}
}
func Object() Value {
	return Value{object}
}
func Array() Value {
	return Value{array}
}
func NewObject() Value {
	return Object().New()
}
func NewArray() Value {
	return Array().New()
}
func toJS(o interface{}) interface{} {
	switch v := o.(type) {
	case []Value:
		refs := make([]interface{}, 0, len(v))
		for _, ref := range v {
			refs = append(refs, ref.JSValue())
		}
		o = refs
	case []Ref:
		refs := make([]interface{}, 0, len(v))
		for _, ref := range v {
			refs = append(refs, ref)
		}
		o = refs
	}
	return o
}
var _ Wrapper = Value{}
type Value struct {
	Ref
}
func (v Value) isZero() bool {
	return v == (Value{})
}
func (v Value) JSValue() Ref {
	return v.Ref
}
func (v Value) String() string {
	if !v.Valid() {
		return ""
	}
	return v.Ref.String()
}
func (v Value) IsNull() bool {
	return v.Ref == null
}
func (v Value) IsUndefined() bool {
	return v.Ref == undefined
}
func (v Value) Valid() bool {
	return !v.isZero() && !v.IsNull() && !v.IsUndefined()
}
func (v Value) Get(name string, path ...string) Value {
	ref := v.Ref.Get(name)
	for _, p := range path {
		ref = ref.Get(p)
	}
	return Value{ref}
}
func (v Value) Set(name string, val interface{}) {
	v.Ref.Set(name, valueOf(val))
}
func (v Value) Index(i int) Value {
	return Value{v.Ref.Index(i)}
}