LoginSignup
11
11

More than 5 years have passed since last update.

次の案件ES6で書いてみたいメモ その2

Last updated at Posted at 2015-07-07

次の案件ES6使ってみようと思ったので勉強記 その2です。

es6-logo.png

(独断と偏見で今度
使いたいなと思ったのを取り上げてるので他の方のいろいろな記事も見てみてください。。)

6、デフォルト引数

デフォルト引数が使えるようです。

sample
// es6
function greeting( word = 'お疲れさまです'){
    console.log(word);
}

greeting(); // お疲れさまです
greeting('おっはー'); // おっはー


/* 
こんな風に変換されてました
es5

'use strict';
function greeting() {
    var word = arguments[0] === undefined ? 'お疲れさまです' : arguments[0];
    console.log(word);
}
*/

7、変数埋め込み

バッククオートで囲んだ文字列の中に変数を埋め込めるようです。
+ ほにゃらら + みたいな連結が楽になりますね。

sample
var name = 'すず';
console.log(`私の名前は${name}です`);
// 私の名前はすずです

8、for/of 文

配列の要素を順番にアクセスするのが楽に

sample
var songs = ['そばかす', '散歩道', 'くじら12号'];

// es5
for (var i = 0; i >= arr.length; i++){
    console.log(arr[i]);
}

// es6
for(let song of songs){
    console.log(song);
}

// そばかす、散歩道、くじら12号

つづく、、、かもしれない

11
11
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
11