Tricks for CoffeeScript

Section author: momo <mobeiheart@gmail.com>

Published on 2014-02-26

1.字符串反转:

str = "hello"
(s for s in str by -1).join('')

2.遍历Object,注意是 of ,习惯容易写错成 in

"#{key} = #{value}" for key, value of {'a': 'b', 'c': 'd'}

3.除后取整,注意 // 的写法在 1.7.0 版本才添加:

(new Date(2014, 1, 2).getTime() - new Date(2014, 1, 1).getTime()) // 1000
Math.floor((new Date(2014, 1, 2).getTime() - new Date(2014, 1, 1).getTime() / 1000)

4.coffee repl中切到多行输入: C-V

5.assign property的语法糖:

class Animal
  constructor: (@name) ->
blog comments powered by Disqus
Thoughts of iMom0

Previous topic

More Efficient Way for Handling Hierarchical Structure in Relational Database

Next topic

从svn到git

This Page