本文整理汇总了Golang中github.com/robertkrimen/otto.Value.IsFunction方法的典型用法代码示例。如果您正苦于以下问题:Golang Value.IsFunction方法的具体用法?Golang Value.IsFunction怎么用?Golang Value.IsFunction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/robertkrimen/otto.Value
的用法示例。
在下文中一共展示了Value.IsFunction方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: formatOneLine
func formatOneLine(v otto.Value, limit int, seen map[otto.Value]bool) (string, error) {
if limit == 0 {
return "...", nil
}
switch {
case v.IsBoolean(), v.IsNull(), v.IsNumber(), v.IsUndefined():
return v.String(), nil
case v.IsString():
return fmt.Sprintf("%q", v.String()), nil
case v.IsFunction():
n, err := v.Object().Get("name")
if err != nil {
return "", err
}
if n.IsUndefined() {
return "function", nil
}
return fmt.Sprintf("function %s", n.String()), nil
case v.IsObject():
switch v.Class() {
case "Array":
return formatArrayOneLine(v, limit, seen)
default:
return formatObjectOneLine(v, limit, seen)
}
default:
return "", fmt.Errorf("couldn't format type %s", v.Class())
}
}
示例2: callHandler
func (ctrl *JsController) callHandler(handler otto.Value, params ...interface{}) (interface{}, error) {
if !handler.IsFunction() {
return nil, fmt.Errorf("Result should be a function, got %v", handler)
}
out, err := handler.Call(handler, params...)
if err != nil {
glog.Errorf("Call resulted in failure %#v", err)
return nil, err
}
obj, err := out.Export()
if err != nil {
glog.Errorf("Failed to extract response %#v", err)
return nil, err
}
return obj, nil
}
示例3: formatIndent
func formatIndent(v otto.Value, width, indent, limit, level, additional int, seen map[otto.Value]bool) (string, error) {
if limit == 0 {
return "...", nil
}
switch {
case v.IsBoolean(), v.IsNull(), v.IsNumber(), v.IsUndefined():
return v.String(), nil
case v.IsString():
return fmt.Sprintf("%q", v.String()), nil
case v.IsFunction():
n, err := v.Object().Get("name")
if err != nil {
return "", err
}
if n.IsUndefined() {
return "function", nil
}
return fmt.Sprintf("function %s", n.String()), nil
case v.IsObject():
if d, err := formatOneLine(v, limit, seen); err != nil {
return "", err
} else if level*indent+additional+len(d) <= width {
return d, nil
}
switch v.Class() {
case "Array":
return formatArray(v, width, indent, limit, level, seen)
default:
return formatObject(v, width, indent, limit, level, seen)
}
default:
return "", fmt.Errorf("couldn't format type %s", v.Class())
}
}