I'm a little baffled. For some reason this won't work:
[1, 2, 3].forEach(function(num) {
console.log(num)
})
I get this error:
TypeError: Cannot call method 'forEach' of undefined
However, this will:
var nums = [1, 2, 3]
nums.forEach(function(num) {
console.log(num)
})
Anyone have any idea what's going on here?
So, it turns out it was because I'm not using semicolons, and the preceding code conflicted.
var foo = 'bar'
[1, 2, 3].forEach(function(num) {
console.log(num)
})
This is valid in both this jsbin: http://jsbin.com/kawatevovabu/1/edit
and in version v0.10.26 of node.js. Perhaps this is a platform issue?