1
函数我有定义为函数如下传递对象到接受PARAM列表
postEvent = (data) ->
throw new Error("category is required for structured events") if not category
throw new Error("action is required for structured events") if not action
$window.submit 'type1', data.category, data.action, data.label, data.property, data.value
需要类别和动作,但剩余的不。如果data
对象不包含给定值,则不应传递它。
我可以使用一个荒谬的if语句数,但我怀疑有更好的方法。 所以我正在寻找一种解开对象值并传递给其他函数的方法。
例子。
data = {category: 'cat1', action: 'action1', value: 1.2}
postEvent(data)
这将导致以下
$window.submit 'type1', 'cat1', 'action1', 1.2