本文整理匯總了Golang中github.com/robertkrimen/otto.Object.Value方法的典型用法代碼示例。如果您正苦於以下問題:Golang Object.Value方法的具體用法?Golang Object.Value怎麽用?Golang Object.Value使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/robertkrimen/otto.Object
的用法示例。
在下文中一共展示了Object.Value方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: fields
func (ctx ppctx) fields(obj *otto.Object) []string {
var (
vals, methods []string
seen = make(map[string]bool)
)
add := func(k string) {
if seen[k] || boringKeys[k] {
return
}
seen[k] = true
if v, _ := obj.Get(k); v.IsFunction() {
methods = append(methods, k)
} else {
vals = append(vals, k)
}
}
// add own properties
ctx.doOwnProperties(obj.Value(), add)
// add properties of the constructor
if cp := constructorPrototype(obj); cp != nil {
ctx.doOwnProperties(cp.Value(), add)
}
sort.Strings(vals)
sort.Strings(methods)
return append(vals, methods...)
}
示例2: gremlinFollowR
func gremlinFollowR(kind string, prevObj *otto.Object, env *otto.Otto, ses *GremlinSession) func(otto.FunctionCall) otto.Value {
return func(call otto.FunctionCall) otto.Value {
call.Otto.Run("var out = {}")
out, _ := call.Otto.Object("out")
out.Set("_gremlin_type", kind)
out.Set("_gremlin_values", call.ArgumentList)
outStrings := concatStringArgs(call)
if len(*outStrings) > 0 {
out.Set("string_args", *outStrings)
}
if len(call.ArgumentList) == 0 {
return prevObj.Value()
}
arg := call.Argument(0)
if isVertexChain(arg.Object()) {
return prevObj.Value()
}
newChain, _ := reverseGremlinChainTo(call.Otto, arg.Object(), "")
out.Set("_gremlin_prev", prevObj)
out.Set("_gremlin_followr", newChain)
embedTraversals(env, ses, out)
if isVertexChain(call.This.Object()) {
embedFinals(env, ses, out)
}
return out.Value()
}
}
示例3: gremlinFollowR
func (wk *worker) gremlinFollowR(kind string, prev *otto.Object, env *otto.Otto) func(otto.FunctionCall) otto.Value {
return func(call otto.FunctionCall) otto.Value {
call.Otto.Run("var out = {}")
out, _ := call.Otto.Object("out")
out.Set("_gremlin_type", kind)
out.Set("_gremlin_values", call.ArgumentList)
args := argsOf(call)
if len(args) > 0 {
out.Set("string_args", args)
}
if len(call.ArgumentList) == 0 {
return prev.Value()
}
arg := call.Argument(0)
if isVertexChain(arg.Object()) {
return prev.Value()
}
newChain, _ := reverseGremlinChainTo(call.Otto, arg.Object(), "")
out.Set("_gremlin_prev", prev)
out.Set("_gremlin_followr", newChain)
wk.embedTraversals(env, out)
if isVertexChain(call.This.Object()) {
wk.embedFinals(env, out)
}
return out.Value()
}
}
示例4: iterOwnKeys
func iterOwnKeys(vm *otto.Otto, obj *otto.Object, f func(string)) {
Object, _ := vm.Object("Object")
rv, _ := Object.Call("getOwnPropertyNames", obj.Value())
gv, _ := rv.Export()
switch gv := gv.(type) {
case []interface{}:
for _, v := range gv {
f(v.(string))
}
case []string:
for _, v := range gv {
f(v)
}
default:
panic(fmt.Errorf("Object.getOwnPropertyNames returned unexpected type %T", gv))
}
}