Javascript 如何将单行咖啡脚本代码转换为多行?

Javascript 如何将单行咖啡脚本代码转换为多行?,javascript,coffeescript,Javascript,Coffeescript,最近我尝试使用咖啡脚本,但我有一些类似的代码 if userAgent.match(/iPad/i) or userAgent.match(/iPhone/i) or userAgent.match(/iPoid/i) or userAgent.match(/Android/i) or userAgent.match(/IEMobile/i) or userAgent.match(/BlackBerry/i) console.log("This is a mobile device")

最近我尝试使用
咖啡脚本
,但我有一些类似的代码

if userAgent.match(/iPad/i) or userAgent.match(/iPhone/i) or userAgent.match(/iPoid/i) or userAgent.match(/Android/i) or userAgent.match(/IEMobile/i) or userAgent.match(/BlackBerry/i)
    console.log("This is a mobile device")
else
    console.log("This is not mobile device")
所以第一行很长,我想让它多行。也许像这样的代码更好,但正如你所知,这在咖啡脚本中是错误的

# This is the wrong code
if userAgent.match(/iPad/i) 
    or userAgent.match(/iPhone/i) 
    or userAgent.match(/iPoid/i) 
    or userAgent.match(/Android/i) 
    or userAgent.match(/IEMobile/i) 
    or userAgent.match(/BlackBerry/i)
    console.log("This is a mobile device")
else
    console.log("This is not mobile device")
或者像这样的一些代码:

# This is also wrong
if userAgent.match(/iPad/i) or 
  userAgent.match(/iPhone/i) or 
  userAgent.match(/iPoid/i) or 
  userAgent.match(/Android/i) or 
  userAgent.match(/IEMobile/i) or 
  userAgent.match(/BlackBerry/i)
    console.log("This is a mobile device")
else
    console.log("This is not mobile device")
if userAgent.match /iPad|iPhone|iPod|Android|IEMobile|BlackBerry/i

那么有什么方法可以纠正这个问题吗?

另外,如果您像这样编写正则表达式,您的境况会好得多:

# This is also wrong
if userAgent.match(/iPad/i) or 
  userAgent.match(/iPhone/i) or 
  userAgent.match(/iPoid/i) or 
  userAgent.match(/Android/i) or 
  userAgent.match(/IEMobile/i) or 
  userAgent.match(/BlackBerry/i)
    console.log("This is a mobile device")
else
    console.log("This is not mobile device")
if userAgent.match /iPad|iPhone|iPod|Android|IEMobile|BlackBerry/i

只需向上移动
。用
结束每一行,而不是从它开始。@AlexPeachey我已经尝试过这个方法,但我无法定义匹配数组并使用带有
任何
方法的库。将其放入
isMobile
方法中。甚至是一个正则表达式。不要试图用不同的方式来完成一行内容。@AlexPeachey对不起,我忘了设置indent@DaveNewton谢谢,你给了我一个很好的建议。掌声我也要说同样的话