zweizhao.github.io

项目,文章,随笔,博客,Markdown,个人网站,人生感悟。

View on GitHub

Range

[0..3] # 1,2,3
[0...3] # 1,2

do

do (arg) ->
	do...

do 后方函数直接执行,并且不会污染外部变量

array

if a in arr

if a not in arr

loop

相当于 while true

@

this 普通函数内 static class 内

::

String::newP = String.prototype.newP

prototype 的缩写

链式比较

healthy = 200 > cholesterol > 60 => `healthy = (200 > cholesterol && cholesterol > 60)

正则表达式块

NUMBER     = ///
  ^ 0b[01]+    |              # binary
  ^ 0o[0-7]+   |              # octal
  ^ 0x[\da-f]+ |              # hex
  ^ \d*\.?\d+ (?:e[+-]?\d+)?  # decimal
///i

=>

var NUMBER;

NUMBER = /^0b[01]+|^0o[0-7]+|^0x[\da-f]+|^\d*\.?\d+(?:e[+-]?\d+)?/i; // binary
// octal
// hex
// decimal

嵌入 js 代码

hi = `function() {
  return [document.title, "Hello JavaScript"].join(": ");
}`
	```
    function time() {
      return `The time is ${new Date().toLocaleTimeString()}`;
    }
	```

三个反斜杠包着 js 代码块