{"action":"created","issue":{"url":"https://api.github.com/repos/super-fool/blog/issues/4","repository_url":"https://api.github.com/repos/super-fool/blog","labels_url":"https://api.github.com/repos/super-fool/blog/issues/4/labels{/name}","comments_url":"https://api.github.com/repos/super-fool/blog/issues/4/comments","events_url":"https://api.github.com/repos/super-fool/blog/issues/4/events","html_url":"https://github.com/super-fool/blog/issues/4","id":385652315,"node_id":"MDU6SXNzdWUzODU2NTIzMTU=","number":4,"title":"js-函数(作用域, this)","user":{"login":"super-fool","id":22948864,"node_id":"MDQ6VXNlcjIyOTQ4ODY0","avatar_url":"https://avatars3.githubusercontent.com/u/22948864?v=4","gravatar_id":"","url":"https://api.github.com/users/super-fool","html_url":"https://github.com/super-fool","followers_url":"https://api.github.com/users/super-fool/followers","following_url":"https://api.github.com/users/super-fool/following{/other_user}","gists_url":"https://api.github.com/users/super-fool/gists{/gist_id}","starred_url":"https://api.github.com/users/super-fool/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/super-fool/subscriptions","organizations_url":"https://api.github.com/users/super-fool/orgs","repos_url":"https://api.github.com/users/super-fool/repos","events_url":"https://api.github.com/users/super-fool/events{/privacy}","received_events_url":"https://api.github.com/users/super-fool/received_events","type":"User","site_admin":false},"labels":[{"id":1140590136,"node_id":"MDU6TGFiZWwxMTQwNTkwMTM2","url":"https://api.github.com/repos/super-fool/blog/labels/JavaScript","name":"JavaScript","color":"7057ff","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-11-29T09:52:44Z","updated_at":"2018-12-03T07:53:47Z","closed_at":null,"author_association":"OWNER","body":"函数声明具有 declaration hoisting (声明提升), 函数表达式没有.\r\nvar 声明变量 具有 variable hoisting(变量提升). let 没有. \r\n"},"comment":{"url":"https://api.github.com/repos/super-fool/blog/issues/comments/443619280","html_url":"https://github.com/super-fool/blog/issues/4#issuecomment-443619280","issue_url":"https://api.github.com/repos/super-fool/blog/issues/4","id":443619280,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0MzYxOTI4MA==","user":{"login":"super-fool","id":22948864,"node_id":"MDQ6VXNlcjIyOTQ4ODY0","avatar_url":"https://avatars3.githubusercontent.com/u/22948864?v=4","gravatar_id":"","url":"https://api.github.com/users/super-fool","html_url":"https://github.com/super-fool","followers_url":"https://api.github.com/users/super-fool/followers","following_url":"https://api.github.com/users/super-fool/following{/other_user}","gists_url":"https://api.github.com/users/super-fool/gists{/gist_id}","starred_url":"https://api.github.com/users/super-fool/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/super-fool/subscriptions","organizations_url":"https://api.github.com/users/super-fool/orgs","repos_url":"https://api.github.com/users/super-fool/repos","events_url":"https://api.github.com/users/super-fool/events{/privacy}","received_events_url":"https://api.github.com/users/super-fool/received_events","type":"User","site_admin":false},"created_at":"2018-12-03T07:53:47Z","updated_at":"2018-12-03T07:53:47Z","author_association":"OWNER","body":"```js\r\nfor (let i = 0 /* 作用域a */; i < 3; console.log(\"in for expression\", i), i++) {\r\n  let i; //这里没有报错，就意味着这里跟作用域a不同\r\n  console.log(\"in for block i: \", i);\r\n  console.log(\"in for block k: \", k);\r\n}\r\n```\r\n\r\n我们改造一下, 在 for 中, 我们可以把 `let i = 0`提出来试一下.\r\n\r\n```js\r\n{\r\n  let i = 0;\r\n  for (i < 3; console.log(\"in for expression\", i); i++) {\r\n    let k = i, i; //这里添加了一个K, 并且精简了下.\r\n    console.log(\"in for block i: \", i);\r\n    console.log(\"in for block k: \", k);\r\n  }\r\n}\r\n```\r\n\r\n---\r\n\r\n### 哦吼, 报错了...排查一下问题...\b🔍\r\n\r\n首先, 看下 for 语句:<br>\r\nfor(语句1; 语句2; 语句\b3)<br>\r\n语句 1（代码块）开始前执行<br>\r\n语句 2  定义运行循环（代码块）的条件<br>\r\n语句 3  在循环（代码块）已被执行之后执行<br>\r\n\r\n我们发现语句2就已经写错了, 那我们改一下:\r\n```js\r\n{\r\n  let i = 0;\r\n  for (;i < 3; console.log(\"in for expression\", i), i++) {\r\n    let k = i,\r\n      i; //这里精简了下.\r\n    console.log(\"in for block i: \", i);\r\n    console.log(\"in for block k: \", k);\r\n  }\r\n}\r\n```\r\n\r\n这时候又报了另一个问题: `i is not defined;`\r\n这又是一个基础问题:\r\n`let k = i, i;`. 这里声明赋值的顺序是**从右至左**.\r\n所以还得改一下.\r\n```js\r\n{\r\n  let i = 0;\r\n  for (;i < 3; console.log(\"in for expression\", i), i++) {\r\n    let i, k = i; //这里精简了下.\r\n    console.log(\"in for block i: \", i);\r\n    console.log(\"in for block k: \", k);\r\n  }\r\n}\r\n```\r\n\r\n"}}
{"actor":{"display_login":"super-fool"}}