当前位置: 首页>>代码示例>>Golang>>正文


Golang js.Object类代码示例

本文整理汇总了Golang中github.com/gopherjs/gopherjs/js.Object的典型用法代码示例。如果您正苦于以下问题:Golang Object类的具体用法?Golang Object怎么用?Golang Object使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Object类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: ok

func ok(kp *js.Object) {
	print("ok")
	print(kp)
	fmt.Printf("%d\n", kp.Get("byteLength").Int())
	x := tmp.Call("view", kp)
	log.Println(x)
}
开发者ID:platinasystems,项目名称:weeb,代码行数:7,代码来源:js.go

示例2: TriggerBindEvent

// TriggerBindEvent connects the giving event with the provided dom target.
func (dm *DOMRenderer) TriggerBindEvent(event *gjs.Object, root *gjs.Object, source *trees.Event) {
	target := event.Get("target")

	children := root.Call("querySelectorAll", source.Target())
	if children == nil || children == gjs.Undefined {
		return
	}

	kids := js.DOMObjectToList(children)
	var match bool

	for _, item := range kids {
		if item != target {
			continue
		}

		match = true
		break
	}

	// if we match then run the listeners registered.
	if match {
		dispatch.Dispatch(trees.EventBroadcast{
			EventID: source.EventID,
			Event:   trees.NewWrapperEvent(event),
		})
	}
}
开发者ID:influx6,项目名称:gu,代码行数:29,代码来源:dom.go

示例3: copyStruct

func copyStruct(dst, src *js.Object, typ Type) {
	fields := jsType(typ).Get("fields")
	for i := 0; i < fields.Length(); i++ {
		prop := fields.Index(i).Get("prop").String()
		dst.Set(prop, src.Get(prop))
	}
}
开发者ID:drawapp8,项目名称:gopherjs,代码行数:7,代码来源:reflect.go

示例4: NewContext

// NewContext takes an HTML5 canvas object and optional context attributes.
// If an error is returned it means you won't have access to WebGL
// functionality.
func NewContext(canvas js.Object, ca *ContextAttributes) (*Context, error) {
	if js.Global.Get("WebGLRenderingContext") == js.Undefined {
		return nil, errors.New("Your browser doesn't appear to support webgl.")
	}

	if ca == nil {
		ca = DefaultAttributes()
	}

	attrs := map[string]bool{
		"alpha":                 ca.Alpha,
		"depth":                 ca.Depth,
		"stencil":               ca.Stencil,
		"antialias":             ca.Antialias,
		"premultipliedAlpha":    ca.PremultipliedAlpha,
		"preserveDrawingBuffer": ca.PreserveDrawingBuffer,
	}
	gl := canvas.Call("getContext", "webgl", attrs)
	if gl == nil {
		gl = canvas.Call("getContext", "experimental-webgl", attrs)
		if gl == nil {
			return nil, errors.New("Creating a webgl context has failed.")
		}
	}
	ctx := new(Context)
	ctx.Object = gl
	return ctx, nil
}
开发者ID:EtienneBruines,项目名称:webgl,代码行数:31,代码来源:webgl_js.go

示例5: ConsoleEvent

func ConsoleEvent(name string, event *jquery.Event, data *js.Object) {
	page := data.Get("toPage").String()
	if page == "[object Object]" {
		page = data.Get("toPage").Call("jqmData", "url").String()
	}
	console.Log("Event: %s, Current page: %s", name, page)
}
开发者ID:flimzy,项目名称:flashback,代码行数:7,代码来源:main.go

示例6: stringable

func stringable(t *js.Object) bool {
	switch t.Get("kind").Int() {
	case boolKind, int8Kind, int16Kind, int32Kind, intKind, uint8Kind, uint16Kind, uint32Kind, uintKind, int64Kind, uint64Kind, float32Kind, float64Kind, stringKind:
		return true
	}
	return false
}
开发者ID:MJKWoolnough,项目名称:gopherjs,代码行数:7,代码来源:encode.go

示例7: sendPayload

func (ws *webSocket) sendPayload(action *Action) (err error) {
	defer func() {
		err = jsError(recover())
	}()

	decodeDataURI := (action.String() == "update_user")

	for _, frame := range action.Payload {
		var data *js.Object = frame

		if decodeDataURI {
			base64 := data.Call("split", ",").Index(1)
			binaryString := js.Global.Call("atob", base64)
			length := binaryString.Length()
			data = js.Global.Get("ArrayBuffer").New(length)
			array := js.Global.Get("Uint8Array").New(data)

			for i := 0; i < length; i++ {
				array.SetIndex(i, binaryString.Call("charCodeAt", i))
			}
		}

		ws.impl.Call("send", data)
	}

	return
}
开发者ID:ninchat,项目名称:ninchat-go,代码行数:27,代码来源:websocket_js.go

示例8: Slice3

func (v Value) Slice3(i, j, k int) Value {
	var (
		cap int
		typ Type
		s   *js.Object
	)
	switch kind := v.kind(); kind {
	case Array:
		if v.flag&flagAddr == 0 {
			panic("reflect.Value.Slice: slice of unaddressable array")
		}
		tt := (*arrayType)(unsafe.Pointer(v.typ))
		cap = int(tt.len)
		typ = SliceOf(tt.elem)
		s = jsType(typ).New(v.object())

	case Slice:
		typ = v.typ
		s = v.object()
		cap = s.Get("$capacity").Int()

	default:
		panic(&ValueError{"reflect.Value.Slice3", kind})
	}

	if i < 0 || j < i || k < j || k > cap {
		panic("reflect.Value.Slice3: slice index out of bounds")
	}

	return makeValue(typ, js.Global.Call("$subslice", s, i, j, k), v.flag&flagRO)
}
开发者ID:drawapp8,项目名称:gopherjs,代码行数:31,代码来源:reflect.go

示例9: copyStruct

func copyStruct(dst, src js.Object, typ Type) {
	fields := jsType(typ).Get("fields")
	for i := 0; i < fields.Length(); i++ {
		name := fields.Index(i).Index(0).Str()
		dst.Set(name, src.Get(name))
	}
}
开发者ID:nvdnkpr,项目名称:gopherjs,代码行数:7,代码来源:reflect.go

示例10: makeValue

func makeValue(t Type, v *js.Object, fl flag) Value {
	rt := t.common()
	if t.Kind() == Array || t.Kind() == Struct || t.Kind() == Ptr {
		return Value{rt, unsafe.Pointer(v.Unsafe()), fl | flag(t.Kind())}
	}
	return Value{rt, unsafe.Pointer(js.Global.Call("$newDataPointer", v, jsType(rt.ptrTo())).Unsafe()), fl | flag(t.Kind()) | flagIndir}
}
开发者ID:drawapp8,项目名称:gopherjs,代码行数:7,代码来源:reflect.go

示例11: cvtDirect

func cvtDirect(v Value, typ Type) Value {
	var srcVal = v.object()
	if srcVal == jsType(v.typ).Get("nil") {
		return makeValue(typ, jsType(typ).Get("nil"), v.flag)
	}

	var val *js.Object
	switch k := typ.Kind(); k {
	case Slice:
		slice := jsType(typ).New(srcVal.Get("$array"))
		slice.Set("$offset", srcVal.Get("$offset"))
		slice.Set("$length", srcVal.Get("$length"))
		slice.Set("$capacity", srcVal.Get("$capacity"))
		val = js.Global.Call("$newDataPointer", slice, jsType(PtrTo(typ)))
	case Ptr:
		if typ.Elem().Kind() == Struct {
			if typ.Elem() == v.typ.Elem() {
				val = srcVal
				break
			}
			val = jsType(typ).New()
			copyStruct(val, srcVal, typ.Elem())
			break
		}
		val = jsType(typ).New(srcVal.Get("$get"), srcVal.Get("$set"))
	case Struct:
		val = jsType(typ).Get("ptr").New()
		copyStruct(val, srcVal, typ)
	case Array, Bool, Chan, Func, Interface, Map, String:
		val = js.InternalObject(v.ptr)
	default:
		panic(&ValueError{"reflect.Convert", k})
	}
	return Value{typ.common(), unsafe.Pointer(val.Unsafe()), v.flag&(flagRO|flagIndir) | flag(typ.Kind())}
}
开发者ID:pombredanne,项目名称:camlistore,代码行数:35,代码来源:reflect.go

示例12: makeValue

func makeValue(t Type, v js.Object, fl flag) Value {
	rt := t.common()
	if t.Size() > ptrSize && t.Kind() != Array && t.Kind() != Struct {
		return Value{rt, unsafe.Pointer(js.Global.Call("go$newDataPointer", v, jsType(rt.ptrTo())).Unsafe()), fl | flag(t.Kind())<<flagKindShift | flagIndir}
	}
	return Value{rt, unsafe.Pointer(v.Unsafe()), fl | flag(t.Kind())<<flagKindShift}
}
开发者ID:hajimehoshi,项目名称:gopherjs,代码行数:7,代码来源:reflect.go

示例13: Register

func (d *Domain) Register(endpoint string, handler *js.Object) *js.Object {
	cb := core.NewID()
	var p promise.Promise

	go func() {
		// From the want wrapper pull out the types they defined,
		// and pass them down into the core.
		h := handler.Get("types")
		tmp := h.Interface()
		types, hasTypes := tmp.([]interface{})

		// handler can either be:
		// 1. an object that contains "types" and "fp" attributes.
		// 2. a naked function, in which case we tell the core that it doesn't
		// care about types.
		handlerFunction := handler
		handlerTypes := []interface{}{nil}
		if hasTypes {
			handlerFunction = handler.Get("fp")
			handlerTypes = types
		}

		if err := d.coreDomain.Register(endpoint, cb, handlerTypes); err == nil {
			d.app.registrations[cb] = handlerFunction
			p.Resolve(nil)
		} else {
			p.Reject(err)
		}
	}()

	return p.Js()
}
开发者ID:kevinherro,项目名称:Exis,代码行数:32,代码来源:main.go

示例14: QuerySelectorAll

// QuerySelectorAll returns the result of querySelectorAll on an object
func QuerySelectorAll(o *js.Object, sel string) []*js.Object {
	if sad := o.Get("querySelectorAll"); sad == nil || sad == js.Undefined {
		return nil
	}

	return DOMObjectToList(o.Call("querySelectorAll", sel))
}
开发者ID:influx6,项目名称:gu,代码行数:8,代码来源:gujs.go

示例15: extractAllLetters

//horrific way to do map(func)
func extractAllLetters(obj js.Object) js.Object {
	result := js.Global.Get("Array").New()
	for i := 0; i < obj.Length(); i++ {
		result.SetIndex(i, extractLetter(obj.Index(i)))
	}
	return result
}
开发者ID:nplanel,项目名称:d3,代码行数:8,代码来源:tutorial.go


注:本文中的github.com/gopherjs/gopherjs/js.Object类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。