如何将一行咖啡脚本代码转换为多行
How to make one line coffee script code to multiline?
我最近尝试使用coffee script
,但我有一些这样的代码
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
相关文章:
- html或java脚本代码在硬盘中创建一个文本文件
- 在Asp.net的TextBox中插入所需文本的java脚本代码
- 是否有脚本/代码可以一次将链接属性添加到多个链接
- 如何在此脚本代码中正确设置此计算和变量
- 如何使用java脚本代码计算禁用按钮的时间
- 脚本代码冲突
- 启用使用java脚本代码在web浏览器中运行的脚本
- 如何将一行咖啡脚本代码转换为多行
- Java 脚本代码 (显示更多 - 显示更少)
- 更改 URL 哈希更改的脚本代码
- 如何使用 javascript 添加脚本代码
- Java 脚本代码不起作用
- 如何递减 Java 脚本代码中的值
- 将 html 代码转换为操作脚本代码
- 如何从 BSF 后处理器的脚本代码进行断言
- Java 脚本代码不起作用
- 基于 Google 电子表格中公式更改的电子邮件脚本代码
- 如何插入不同的<脚本>代码
- CKEDITOR - 启用插入 Java 脚本代码
- 将 ajax 回调脚本代码放在 rails 3.1 中的位置