-
Notifications
You must be signed in to change notification settings - Fork 6
/
arguments.go
29 lines (24 loc) · 1017 Bytes
/
arguments.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package javascript
import (
"encoding/gob"
"strings"
)
// Arguments represents a list of javascript function arguments. We can output this as javascript, or as JSON, which
// gets sent to the goradd javascript during Ajax calls and unpacked there.
// Primitive types get expressed as constant values in javascript. If you want to represent the name of variable,
// us a NewJsCode object. NewFunctionCall can be represented using the NewFunctionCall object or the NewClosure object, depending on whether
// you want the output of the function now, or later.
type Arguments []interface{}
// JavaScript implements the JavaScripter interface and returns the arguments as a comma separated list of values
// suitable to put in JavaScript function arguments.
func (a Arguments) JavaScript() string {
var values []string
for _, v := range a {
values = append(values, ToJavaScript(v))
}
return strings.Join(values, ",")
}
func init() {
// Register objects so they can be serialized
gob.Register(Arguments{})
}