Skip to content

Instantly share code, notes, and snippets.

@tatsuro-ueda
Created September 6, 2012 02:46
Show Gist options
  • Save tatsuro-ueda/3650233 to your computer and use it in GitHub Desktop.
Save tatsuro-ueda/3650233 to your computer and use it in GitHub Desktop.
CoffeeScriptまとめ

##CoffeeScriptまとめ

###コメント

これはコメント

複数行のコメント。たぶん、ライセンス

###はまりどころ

JavaScriptを包んでいるコメントタグがちゃんと閉じていないとコメントタグ(開始)以降は無視される -->

###switch制御

switch val when 1 ……… when 2 then ……… when 3,4,5 #いくつかをまとめたいときは,区切り ……… else ………

###do while制御

x = 8 loop document.writeln('xの値は' + x) x++ break if(x >= 10)

###例外処理

x = 1 y = 0 try #if y == 0 # throw new Error '0で除算しようとしました' z = x / y catch e document.writeln e.message finally document.writeln '処理が終了しました'

###正規表現とForループ

p = /http(s)?://([\w-]+.)+[\w-]+(/[\w- ./?%&=]*)?/gi str = 'サポートサイトはhttp://www.wings.msn.to/です' str += 'サンプル紹介サイトはHTTP://www.web-deli.com/もよろしく!' result = str.match p for match in result document.writeln(match)

###サブマッチ文字列

正規表現パターンの中に丸括弧で示された部分(サブマッチパターン)に合致した部分のこと

###RegExp関連のメソッド

  • String.match
  • exec
  • test
  • search
  • replace
  • String.split

###匿名オブジェクト

obj = new Object obj.name = 'Tom' obj.birth = new Date(2005, 7, 15) obj.old = 5

document.writeln obj.name

###Globalオブジェクト

parseFloat parseInt Number String Boolean encodeURI encodeURIComponent(より強いエスケープ) decodeURI decodeURIComponent

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment