ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、视频、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
##coffeescript >http://coffeescript.org/ >http://coffee-script.org/ CoffeeScript 尝试用简洁的方式展示 JavaScript 优秀的部分. ##安装 ``` sudo npm install -g coffee-script ``` ##语法: ``` # 变量赋值 num = 1 isRight = true obj = a: 5 b: 'str' fun: -> @a console.log(obj.fun()) # 函数定义 func = -> obj.a + num # 函数默认值 func2 = (name, age = 20) -> console.log(name + ': ' + age) # 简单if str = 'str' str += 'abc' if isRight # 标准if..else if str is 'str' str += 'abc' else if str is 'abc' str += 'str' age = 12 # 范围判断 isStudent = 10 <age < 25 console.log(isStudent) # 数组定义 arr = [1, 3, 5, 7, 9] # 数组遍历 for item in arr console.log(item) # while 循环 console.log(arr.pop()) while arr.length > 0 # 推导 obj2 = { key: 'abc' value: 'def' class: 'This is class' } console.log key,value for key, value of obj2 when key isnt 'key' func2('XiaoMing') # 自执行函数 do -> console.log('Self call.') nullStr = undefined if nullStr? console.log('nullStr is null') # 如果null或者undefined,那么赋值 str ?= 'AA' func3 = `function abc(){console.log('func3');}` func3() try `a5 = abc` catch err console.log(err) finally console.log('Finally.') ### Multi ### ``` ##webStorm中 1.新建 coffeescript File 2.Add Watcher(设置编译) 3.设置Program目录