turingschool-examples / intermission-assignments

33 stars 218 forks source link

Speaking JavaScript #25

Closed worace closed 8 years ago

worace commented 9 years ago

Discuss Speaking JavaScript, especially following chapters here:

rasensio1 commented 8 years ago

Makes me appreciate the default parameter setting in Ruby! Syntax for running a function (function () {}()) seems sort of tedious

7hoenix commented 8 years ago

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?

selfup commented 8 years ago

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!