2011/06/28

Coffescript iteration caveat

In Cofffeescript, there are 2 built-in sytanxes for interation. for .. of .. / for .. in .. (by ..)

In Pragmatic Coffeescript book, the author says,

" Why have a seperate syntax? Why not just use for key, value of array?Because there're nothing stopping an array from having extra methods or data. If you want the whole shebang, then sure, use of. But if you just want to treat the array as an array, use in -- you will onlyget array[0], array[1], etc., up to array[array.length-1], in that order"




blog comments powered by Disqus