我如何正确地做coffeescript或=?

时间:2013-01-03 13:53:25

标签: jquery coffeescript operators dom-manipulation

我想要做的是同时获取一个项目列表,隐藏它们并将它们分配给这样的变量:

jQuery ->
    client_list or= $('.client-list').find('.actions').hide()

但是这会中断并且ActionController说Error: the variable "client_list" can't be assigned with ||= because it has not been defined.

我该如何解决这个问题?这甚至可能吗?

1 个答案:

答案 0 :(得分:1)

你在coffeescript中这样做的方式是这样的:

client_list = client_list ? $('.client-list').find('.actions').hide()

但是我认为这样做没有意义,除非您稍后在运行时重用该调用(如延迟加载)。

所以实际上在这种情况下根本不需要使用?