{"action":"opened","issue":{"url":"https://api.github.com/repos/jashkenas/coffeescript/issues/4062","labels_url":"https://api.github.com/repos/jashkenas/coffeescript/issues/4062/labels{/name}","comments_url":"https://api.github.com/repos/jashkenas/coffeescript/issues/4062/comments","events_url":"https://api.github.com/repos/jashkenas/coffeescript/issues/4062/events","html_url":"https://github.com/jashkenas/coffeescript/issues/4062","id":101569006,"number":4062,"title":"propose a functional let grammar","user":{"login":"winterland1989","id":1295998,"avatar_url":"https://avatars.githubusercontent.com/u/1295998?v=3","gravatar_id":"","url":"https://api.github.com/users/winterland1989","html_url":"https://github.com/winterland1989","followers_url":"https://api.github.com/users/winterland1989/followers","following_url":"https://api.github.com/users/winterland1989/following{/other_user}","gists_url":"https://api.github.com/users/winterland1989/gists{/gist_id}","starred_url":"https://api.github.com/users/winterland1989/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/winterland1989/subscriptions","organizations_url":"https://api.github.com/users/winterland1989/orgs","repos_url":"https://api.github.com/users/winterland1989/repos","events_url":"https://api.github.com/users/winterland1989/events{/privacy}","received_events_url":"https://api.github.com/users/winterland1989/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-08-18T04:20:12Z","updated_at":"2015-08-18T04:20:12Z","closed_at":null,"body":"Sad to see `let` in ES2015 went to a different way than spiderMonkey's [early impelementations](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Statements/let), but anyway this `let` thing is quite nice thing in syntax if done right.\r\nHere is my little proposal and kind of roadmap how we going to make it. hope this will make some language enhancement and clear some es2015 issue.\r\n\r\n+ let ... in statements\r\n\r\nAt top level or Inside functions, we often have statements to do side effect, so\r\n```coffee\r\nzipWith = (xs, ys, fn) ->\r\n  result = []\r\n  let xl = xs.length, yl = y.length in\r\n    if xl >= yl\r\n       ...\r\n    else \r\n       ...\r\n  result\r\n```\r\nwill compile to an IIFE\r\n```js\r\nvar zipWith = function(xs, ys, fn){\r\n  var result = []\r\n  (function(xl, yl){\r\n    if(xl >= yl){\r\n       ...\r\n    }else{\r\n       ...\r\n    }\r\n  })(xs.length, y.length);\r\n  return result;\r\n}\r\n```\r\nwhen es2015 is ready and perform well, we turn that into\r\n```js\r\nvar zipWith = function(xs, ys, fn){\r\n  var result = []\r\n  {\r\n    let xl = xs.length, yl = y.length;\r\n    if(xl >= yl){\r\n       ...\r\n    }else{\r\n       ...\r\n    }\r\n  }\r\n  return result;\r\n}\r\n```\r\n\r\n+ let ... in expressions\r\n\r\nalways turn them into a IIFE, just like a `do` notion, but more readable than `do`, isn't it?\r\n\r\n+ special for let\r\n\r\nsince `for` statements can do assignment, maybe we can add a special `for let` to make it less surprise?\r\n```coffee\r\nfor let i in [1..100]\r\n  ...\r\n```\r\nwill turn into\r\n```js\r\n(funtion(){\r\n  var i;\r\n  for(i = 1; i<=100; i++){\r\n    (function(i){\r\n      ...\r\n    })(i);\r\n  }\r\n})()\r\n```\r\nwhen es2015 is ready and perform well, we turn that into\r\n```js\r\nfor(let i = 1; i<=100; i++){\r\n  ...\r\n}\r\n```\r\n\r\nSo for now, this is purely a syntax sugar, while in furture, we can have some potential performance gain."}}