News for hackers. Stuff that matters.
Re:Overview of JavaScript ES6 features by z3t4 on Monday October 24, 2016 @02:47PM (#12781622)
> With the asynchronous nature of Javascript, it's theoretically possible for you to declare a variable with `var`, assign it a value, then immediately use that value and find that it's different than what you expected

Can you give an example ? My understanding is that the closure freeze the variable in the time the function was called. It can happen if you do not use a closure (function) though.

Re:Overview of JavaScript ES6 features by Meegul on Monday October 24, 2016 @03:04PM (#12781799)
Here's a post on Stackoverflow that can explain it better than I can: http://stackoverflow.com/questions/21363295/understanding-ja...
Re:Overview of JavaScript ES6 features by z3t4 on Wednesday October 26, 2016 @07:55AM (#12795704)
Here's how you should do it:

  for(var i=0; i<=3; i++) count(i);

Or a real world example:

  for(var i=0; i<texture.length; i++) createPattern(i);

  function createPattern(i) {
    texture[i].onload = function() {
      pattern[i] = ctx.createPattern(texture[i], 'repeat');
    }
  }
I've made a blog post about closures: http://www.webtigerteam.com/johan/en/blog/closure_en.htm

It would be cool to write like this (but you cant):

  pattern = texture.map(t => t.onload => ctx.createPattern(t, 'repeat'))
Re:Overview of JavaScript ES6 features by Roboprog on Wednesday October 26, 2016 @11:36AM (#12797325)
Javascript closures are like Ruby blocks and closures: you get to "touch", as well as "look" - and also see "touches" that happened in between times elsewhere.