簡易1行記法

概要

条件に対し処理が1行しかない場合はif文と処理を1行にまとめる


サンプル

CoffeeScript

# 変数
str = ""
 
# 判定
if !a? then str = "変数未定義じゃね?"
 
# セレクタでエレメントを取得
sample = document.querySelector("#sample")
 
# パラメータ連結
sample.innerHTML = str
 
 

javascript

// Generated by CoffeeScript 1.3.3
var sample, str;
 
str = "";
 
if (!(typeof a !== "undefined" && a !== null)) {
  str = "変数未定義じゃね?";
}
 
sample = document.querySelector("#sample");
 
sample.innerHTML = str;
 
 


最終更新:2012年08月29日 22:11