{"action":"closed","issue":{"url":"https://api.github.com/repos/whps/whps.github.io/issues/38","repository_url":"https://api.github.com/repos/whps/whps.github.io","labels_url":"https://api.github.com/repos/whps/whps.github.io/issues/38/labels{/name}","comments_url":"https://api.github.com/repos/whps/whps.github.io/issues/38/comments","events_url":"https://api.github.com/repos/whps/whps.github.io/issues/38/events","html_url":"https://github.com/whps/whps.github.io/issues/38","id":125594248,"number":38,"title":"es6 箭头函数 中的 this 和 arguments 是词法作用域","user":{"login":"whps","id":8290205,"avatar_url":"https://avatars.githubusercontent.com/u/8290205?v=3","gravatar_id":"","url":"https://api.github.com/users/whps","html_url":"https://github.com/whps","followers_url":"https://api.github.com/users/whps/followers","following_url":"https://api.github.com/users/whps/following{/other_user}","gists_url":"https://api.github.com/users/whps/gists{/gist_id}","starred_url":"https://api.github.com/users/whps/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/whps/subscriptions","organizations_url":"https://api.github.com/users/whps/orgs","repos_url":"https://api.github.com/users/whps/repos","events_url":"https://api.github.com/users/whps/events{/privacy}","received_events_url":"https://api.github.com/users/whps/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/whps/whps.github.io/labels/%E7%BB%8F%E9%AA%8C","name":"经验","color":"84b6eb"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-01-08T11:33:47Z","updated_at":"2016-02-25T13:01:20Z","closed_at":"2016-02-25T13:01:20Z","body":"```\r\nfunction a() {\r\n return () => { return arguments }\r\n}\r\n\r\nfunction b() {\r\n  return function() { return arguments }\r\n}\r\n\r\na(1)(1,2,3) // return [1]\r\nb(1)(1,2,3) // return [1,2,3]\r\n\r\n```\r\n\r\n这是今天遇到的一个小问题\r\n```\r\nfunction use(stub_name)  {\r\n  return function(path/*, actions*/) {\r\n    var keys = [];\r\n    var pattern;\r\n    var actions;\r\n\r\n    console.log(arguments);\r\n\r\n    if (typeof path === 'string') {\r\n\r\n      pattern = path2regex(path, keys);\r\n      actions = Array.prototype.slice.call(arguments, 1);\r\n\r\n    } else if (typeof path === 'function') {\r\n\r\n      pattern = path2regex('/', keys);\r\n      actions = Array.prototype.slice.call(arguments);\r\n\r\n    } else {\r\n\r\n      throw \"unknown route config\";\r\n    }\r\n\r\n    _routes[stub_name].push({keys, pattern, actions});\r\n\r\n    return this;\r\n  }\r\n}\r\n```\r\nuse 函数始终抓到的 arguments 是 stub_name, 我还一度怀疑是不是 node 解释器问题, 甚至还重启了机器\r\n原来是词法作用域, fuck...\r\n\r\n> 那么问题来了, 在什么情况下用 箭头函数好呢, 个人认为是这样的\r\n\r\n```\r\nClass A{\r\n  method1() {\r\n    this.list.map((i) => { return this.handle(i) })\r\n  }\r\n}\r\n// 在这种情况下是比较合适的, 即在类上的某个方法里需要调 列表方法 时, 不用bind 或者 传入 this 了\r\n// 有一点很重要 给箭头函数apply 和 call 并不起作用！\r\n// 那么在编码中同学们常常忘掉这个特性犯一些错误,\r\n// 我的做法是尽量不用箭头函数,(当然对于十分清楚自己的每一行代码是在做什么的同学可以忽略这条\r\n```"}}