CoffeeScript:在函数调用中展开数组 [英] CoffeeScript: Expand array in function call

查看:157
本文介绍了CoffeeScript:在函数调用中展开数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Ruby中,我可以调用数组元素作为位置参数的方法,例如

In Ruby I can call methods with array elements used as positional parameters like this

method(fixed_arg1, fixed_arg2, *array_of_additional_args)

这里*操作符扩展数组。

Here the "*" operator expands the array in place.

我想在CoffeeScript中做同样的事,但没有找到办法。具体来说,我想在调用jQuery函数时传递额外的参数。

I'm trying to do the same in CoffeeScript, but haven't found a way. Specifically, I want to pass additional arguments in a call to a jQuery function

$('#my-element').toggle(true, *config.toggleOptions)

上面的语法不工作,显然,寻找一种方法。

The syntax above does not work, obviously, and I'm looking for a way that does.

推荐答案

尝试

$('#my-element').toggle(true, config.toggleOptions...)

这篇关于CoffeeScript:在函数调用中展开数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆