Closed worace closed 8 years ago
Makes me appreciate the default parameter setting in Ruby! Syntax for running a function (function () {}()) seems sort of tedious
Question:
Very bottom of Chapter 16 on Closures has this example:
function f() { var result = []; for (var i=0; i<3; i++) { (function () { // step 1: IIFE var pos = i; // step 2: copy var func = function () { return pos; }; result.push(func); }()); } return result; } console.log(f()[1]()); // 1
What is the [1] doing in this function call?
Hey @rasensio1 you should check out ES6 syntax. It clears a lot of things up.
for example:
var adding = function(paramOne) { var addingNumber = 2; return paramOne + addingNumber; }
can now be:
var adding = (paramOne) => { let addingNumber = 2 return paramOne + addingNumber }
That is just the beginning of the sweet syntax for ES6!
Discuss Speaking JavaScript, especially following chapters here: