首页 > 代码库 > coffeeScript demo
coffeeScript demo
#可以直接在浏览器嵌入coffee-script.js 解析xx.coffee脚本,但真正正式使用时不建议这样使用,coffee-script.js下载地址:http://coffeescript.org/extras/coffee-script.js
#本地安装coffee 可以把写好的xx.coffee 编译成 xx.js 命令:coffee -c xx.coffee
#变量
myVar = 1
#数组
myArray = [1, 2, 3, 4, 5]
#对象
leader =
name: "wj"
age: 25
alert(leader.name)
#函数 if x == null x default 6
square = (x = 6) ->
x * x
alert(square(myVar))
alert(square())
#判断
#三目运算
myVar = 0 if leader.name == ‘wj‘
alert(myVar)
if myVar == 0
myVar = 1
else if myVar == 1
myVar = 2
else
myVar = 3
#遍历
myVar = myVar + x for x in myArray;
myVar = myVar+x for x in myArray when x == 5
alert(myVar)
#本地安装coffee 可以把写好的xx.coffee 编译成 xx.js 命令:coffee -c xx.coffee
#变量
myVar = 1
#数组
myArray = [1, 2, 3, 4, 5]
#对象
leader =
name: "wj"
age: 25
alert(leader.name)
#函数 if x == null x default 6
square = (x = 6) ->
x * x
alert(square(myVar))
alert(square())
#判断
#三目运算
myVar = 0 if leader.name == ‘wj‘
alert(myVar)
if myVar == 0
myVar = 1
else if myVar == 1
myVar = 2
else
myVar = 3
#遍历
myVar = myVar + x for x in myArray;
myVar = myVar+x for x in myArray when x == 5
alert(myVar)
coffeeScript demo
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。