{"action":"closed","issue":{"url":"https://api.github.com/repos/ruanyf/jstutorial/issues/136","repository_url":"https://api.github.com/repos/ruanyf/jstutorial","labels_url":"https://api.github.com/repos/ruanyf/jstutorial/issues/136/labels{/name}","comments_url":"https://api.github.com/repos/ruanyf/jstutorial/issues/136/comments","events_url":"https://api.github.com/repos/ruanyf/jstutorial/issues/136/events","html_url":"https://github.com/ruanyf/jstutorial/issues/136","id":155880181,"number":136,"title":"函数名的提升的问题","user":{"login":"zhizunbao84","id":2263408,"avatar_url":"https://avatars.githubusercontent.com/u/2263408?v=3","gravatar_id":"","url":"https://api.github.com/users/zhizunbao84","html_url":"https://github.com/zhizunbao84","followers_url":"https://api.github.com/users/zhizunbao84/followers","following_url":"https://api.github.com/users/zhizunbao84/following{/other_user}","gists_url":"https://api.github.com/users/zhizunbao84/gists{/gist_id}","starred_url":"https://api.github.com/users/zhizunbao84/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zhizunbao84/subscriptions","organizations_url":"https://api.github.com/users/zhizunbao84/orgs","repos_url":"https://api.github.com/users/zhizunbao84/repos","events_url":"https://api.github.com/users/zhizunbao84/events{/privacy}","received_events_url":"https://api.github.com/users/zhizunbao84/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-05-20T03:28:44Z","updated_at":"2016-05-20T15:38:52Z","closed_at":"2016-05-20T15:38:52Z","body":"在http://javascript.ruanyifeng.com/grammar/function.html中  1.5  函数名的提升中\r\n我在chorme的命令行中测试的\r\n问题一                  =======================\r\n文章原文：\r\n\r\nf();\r\nvar f = function (){};\r\n// TypeError: undefined is not a function\r\n上面的代码等同于下面的形式。\r\n\r\nvar f;\r\nf();\r\nf = function () {};\r\n上面代码第二行，调用f的时候，f只是被声明了，还没有被赋值，等于undefined，所以会报错。\r\n\r\n我的测试结果\r\nf();\r\nvar f = function (){};\r\n\r\n上面的代码返回undefined\r\n\r\nvar f;\r\nf();\r\nf = function () {};\r\n返回：\r\nfunction () {}\r\n\r\n这个结果跟文章中的不同啊？\r\n\r\n问题二                  =======================\r\n文章原文：\r\n如果同时采用function命令和赋值语句声明同一个函数，最后总是采用赋值语句的定义。\r\n\r\nvar f = function() {\r\n  console.log('1');\r\n}\r\n\r\nfunction f() {\r\n  console.log('2');\r\n}\r\n\r\nf() // 1\r\n\r\n我的测试结果：\r\nVM155:4 Uncaught SyntaxError: Identifier 'f' has already been declared\r\n    at Object.InjectedScript._evaluateOn (<anonymous>:878:140)\r\n    at Object.InjectedScript._evaluateAndWrap (<anonymous>:811:34)\r\n    at Object.InjectedScript.evaluate (<anonymous>:667:21)"}}
{"actor":{"display_login":"ruanyf"}}