{"action":"created","issue":{"url":"https://api.github.com/repos/rdmclin2/TechDiary/issues/1","repository_url":"https://api.github.com/repos/rdmclin2/TechDiary","labels_url":"https://api.github.com/repos/rdmclin2/TechDiary/issues/1/labels{/name}","comments_url":"https://api.github.com/repos/rdmclin2/TechDiary/issues/1/comments","events_url":"https://api.github.com/repos/rdmclin2/TechDiary/issues/1/events","html_url":"https://github.com/rdmclin2/TechDiary/issues/1","id":175221867,"number":1,"title":"2016年9月日报","user":{"login":"rdmclin2","id":4705237,"avatar_url":"https://avatars.githubusercontent.com/u/4705237?v=3","gravatar_id":"","url":"https://api.github.com/users/rdmclin2","html_url":"https://github.com/rdmclin2","followers_url":"https://api.github.com/users/rdmclin2/followers","following_url":"https://api.github.com/users/rdmclin2/following{/other_user}","gists_url":"https://api.github.com/users/rdmclin2/gists{/gist_id}","starred_url":"https://api.github.com/users/rdmclin2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rdmclin2/subscriptions","organizations_url":"https://api.github.com/users/rdmclin2/orgs","repos_url":"https://api.github.com/users/rdmclin2/repos","events_url":"https://api.github.com/users/rdmclin2/events{/privacy}","received_events_url":"https://api.github.com/users/rdmclin2/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/rdmclin2/TechDiary/labels/%E6%97%A5%E6%8A%A5","name":"日报","color":"f9d0c4"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":17,"created_at":"2016-09-06T11:16:59Z","updated_at":"2016-09-22T03:52:56Z","closed_at":null,"body":"延续在支付宝实习时的良好习惯，记日报。8月日报从8月27日开始记录，合在9月的日报中"},"comment":{"url":"https://api.github.com/repos/rdmclin2/TechDiary/issues/comments/248804504","html_url":"https://github.com/rdmclin2/TechDiary/issues/1#issuecomment-248804504","issue_url":"https://api.github.com/repos/rdmclin2/TechDiary/issues/1","id":248804504,"user":{"login":"rdmclin2","id":4705237,"avatar_url":"https://avatars.githubusercontent.com/u/4705237?v=3","gravatar_id":"","url":"https://api.github.com/users/rdmclin2","html_url":"https://github.com/rdmclin2","followers_url":"https://api.github.com/users/rdmclin2/followers","following_url":"https://api.github.com/users/rdmclin2/following{/other_user}","gists_url":"https://api.github.com/users/rdmclin2/gists{/gist_id}","starred_url":"https://api.github.com/users/rdmclin2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rdmclin2/subscriptions","organizations_url":"https://api.github.com/users/rdmclin2/orgs","repos_url":"https://api.github.com/users/rdmclin2/repos","events_url":"https://api.github.com/users/rdmclin2/events{/privacy}","received_events_url":"https://api.github.com/users/rdmclin2/received_events","type":"User","site_admin":false},"created_at":"2016-09-22T03:52:55Z","updated_at":"2016-09-22T03:52:55Z","body":"# 9-21\r\n- 感冒中...\r\n- 参加腾讯面试，遇到实习时的面试官，直接说我没什么好问你的，你有什么要问我的吗？问了几个问题然后就回去了...一点收获都没有\r\n- 整理《你不知道的JavaScript》闭包部分关键概念\r\n一个典型的闭包:\r\n```\r\nfunction foo() {\r\n  var a = 2;\r\n  function bar() {\r\n    console.log(a);\r\n  }\r\n  return bar;\r\n}\r\n\r\nvar baz = foo();\r\nbaz(); // 2\r\n\r\n// 另一个\r\nfunction wait(message){\r\n      setTimeout(function time(){\r\n          console.log(message);\r\n      }, 1000);\r\n  }\r\n  wait(\"hello clousre\");\r\n```\r\n\r\n```\r\n- 当函数可以记住并访问所在的词法作用域时，就产生了闭包，即使函数是在当前词法作用域之外执行。\r\n- 闭包的神奇之处在于可以阻止foo的内部作用域被销毁，没有被回收，bar依然持有对该作用域的引用，而这个引用就叫做闭包\r\n- 闭包使得函数可以继续访问定义时的词法作用域\r\n- 本质上无论何时何地，如果将（访问它们各自词法作用域的）函数当做第一级的值并导出传递，就会看到闭包在这些函数中的应用\r\n- 那么闭包有哪些应用呢？其实包括定时器，事件监听器，Ajax请求，跨窗口通信，Web Workers或者任何其他的异步(或者同步)任务中，只要使用回调函数，实际上就是在使用闭包!\r\n- 从技术上来讲，闭包是发生在定义时的,IIFE是最常用来创建可以被封闭起来的闭包的工具\r\n- 一个典型的易错场景循环闭包,我们需要用IIFE为每一个迭代生成一个新的作用域，并在作用域中保存正确的值,如下:\r\nfor( var i = 1; i <=5; i++) {\r\n  (function(j) {\r\n    setTimeout( function timer() {\r\n      console.log(j);\r\n      }, 1000 * j);\r\n    }\r\n  )(i);\r\n}\r\n- let可以劫持块作用域，并且在这个块作用域中声明一个变量,本质上是将一个块转换成了一个可以被关闭的作用域,for循环头部的let变量在循环过程中不止被声明一次，每次迭代都会声明。随后的每个迭代都会使用上一个迭代结束时的值来初始化这个变量,所以上面的代码可以用下面的代码代替\r\n for(let i=1; i<6; i++){\r\n    setTImeout(function time(){\r\n        console.log(i)\r\n    }, i*1000)\r\n  }\r\n- 模块机制利用了闭包的强大威力。模块的两个特征： (1)为内部作用域调用一个包装函数; (2) 包装函数的返回值必须至少包括一个队内部函数的引用，这样就会创建涵盖整个包装函数内部作用域的闭包.\r\n```"}}
{"actor":{"display_login":"rdmclin2"}}