演算子
演算子の優先順位(低い順)
Section titled “演算子の優先順位(低い順)”pipe— パイプラインor— 論理ORand— 論理ANDeq/neq/not eq/is/instanceof— 等価 / 型チェックlt/gt/le(lt eq) /ge(gt eq) — 比較add/sub— 加算 / 減算mul/div/mod— 乗算 / 除算 / 剰余pow— べき乗- 単項:
not/neg/typeof/await/delete/new - 後置:
.アクセス /[args]呼び出し /asキャスト - 基本: リテラル、識別子、括弧
パイプライン
Section titled “パイプライン”data pipe filterdata pipe filter pipe mapdata pipe transform[extra-arg]data pipe .method[arg]コンパイル結果:
filter(data)map(filter(data))transform(data, extraArg)data.method(arg)const x be 42let y be 10y be 20a add b -- a + ba sub b -- a - ba mul b -- a * ba div b -- a / ba mod b -- a % ba pow b -- a ** bneg x -- -xeq と is は同じように使えます。右辺が型名(string, number, null, 大文字始まりのクラス名など)の場合は型チェックになり、それ以外は厳密等価比較(===)になります。
不等価には neq または not eq を使います。以下はどちらも le と同じ意味です: lt eq。以下はどちらも ge と同じ意味です: gt eq。
a eq b -- a === ba neq b -- a !== ba not eq b -- a !== b(別の書き方)a lt b -- a < ba gt b -- a > ba le b -- a <= ba lt eq b -- a <= b(別の書き方)a ge b -- a >= ba gt eq b -- a >= b(別の書き方)
-- eq と is は混同して使えるa eq b -- a === b(値の比較)a is b -- a === b(値の比較)a eq string -- typeof a === "string"(型チェック)a is string -- typeof a === "string"(型チェック)..(包含)と ...(排他)を使って数値範囲から配列を生成します:
const a be [0..5] -- [0, 1, 2, 3, 4, 5]const b be [0...5] -- [0, 1, 2, 3, 4]const c be [1..10] -- [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]const d be [1...10] -- [1, 2, 3, 4, 5, 6, 7, 8, 9]スライス(切り出し)
Section titled “スライス(切り出し)”..(包含)または ...(排他)をブラケットアクセス内で使い、配列の一部を切り出します:
const numbers be [0, 1, 2, 3, 4, 5, 6]const middle be numbers[2..4] -- [2, 3, 4]const partial be numbers[1...4] -- [1, 2, 3]スプライス(部分置換)
Section titled “スプライス(部分置換)”スライスに代入することで配列の一部を置換できます:
numbers[2..4] be [///a///; ///b///; ///c///]-- numbers は [0, 1, "a", "b", "c", 5, 6] になります配列から変数に値を取り出します:
const weather be [///Sunny///; ///Rainy///]const [today; tomorrow] be weather
-- 変数の値を入れ替える[today; tomorrow] be [tomorrow; today]a and b -- a && ba or b -- a || bnot x -- !xeq と is はどちらも型名の前に置くと型チェックとして機能します。
x is string -- typeof x === "string"x eq string -- typeof x === "string"x is null -- x === nullx is MyClass -- x instanceof MyClassx instanceof Y -- x instanceof Ytypeof x -- typeof x