44
40

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CoffeeScriptのfor

Last updated at Posted at 2013-02-19

なんでこういう構文にしたんだろう?
ArrayObjectfor infor ofで区別しなければならないのもアレだし、
csでfor inしたものが、jsでforになって、
csでfor ofしたものが、jsでfor inになるとか、
value``indexkey``valueの順番とか、
ちょっとややこい。

for value in array
  hoge

for value, index in array
  hoge

for key of object
  hoge

for key, value of object
  hoge

吐き出すJavaScirptは

var index, key, value, _i, _j, _len, _len1;

for (_i = 0, _len = array.length; _i < _len; _i++) {
  value = array[_i];
  hoge;

}

for (index = _j = 0, _len1 = array.length; _j < _len1; index = ++_j) {
  value = array[index];
  hoge;

}

for (key in object) {
  hoge;

}

for (key in object) {
  value = obj[key];
  hoge;

}
44
40
3

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
44
40

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?