を受け入れる関数にオブジェクトを渡す次のように私は定義された機能を持っているの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)
これはあなたがdestructuringを使用することができ、次の
$window.submit 'type1', 'cat1', 'action1', 1.2