{"action":"opened","issue":{"url":"https://api.github.com/repos/openfl/openfl-js/issues/1","repository_url":"https://api.github.com/repos/openfl/openfl-js","labels_url":"https://api.github.com/repos/openfl/openfl-js/issues/1/labels{/name}","comments_url":"https://api.github.com/repos/openfl/openfl-js/issues/1/comments","events_url":"https://api.github.com/repos/openfl/openfl-js/issues/1/events","html_url":"https://github.com/openfl/openfl-js/issues/1","id":280648676,"number":1,"title":"Use arrow functions to improve samples code","user":{"login":"elsassph","id":297963,"avatar_url":"https://avatars2.githubusercontent.com/u/297963?v=4","gravatar_id":"","url":"https://api.github.com/users/elsassph","html_url":"https://github.com/elsassph","followers_url":"https://api.github.com/users/elsassph/followers","following_url":"https://api.github.com/users/elsassph/following{/other_user}","gists_url":"https://api.github.com/users/elsassph/gists{/gist_id}","starred_url":"https://api.github.com/users/elsassph/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elsassph/subscriptions","organizations_url":"https://api.github.com/users/elsassph/orgs","repos_url":"https://api.github.com/users/elsassph/repos","events_url":"https://api.github.com/users/elsassph/events{/privacy}","received_events_url":"https://api.github.com/users/elsassph/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-12-08T23:37:16Z","updated_at":"2017-12-08T23:37:16Z","closed_at":null,"author_association":"NONE","body":"In ES6/TypeScript you can improve you samples by using arrow functions - these functions maintain the scope of `this` references:\r\n\r\n1. Event handlers\r\n```\r\nobj.addEventListener('foo', this.handler.bind(this));\r\n...\r\nprivate hander(event) {...}\r\n```\r\nShould be written:\r\n```\r\nobj.addEventListener('foo', this.handler);\r\n...\r\nprivate hander = (event) => {...}\r\n```\r\n\r\n2. Anonymous function scope\r\n```\r\nvar self = this;\r\nobj.addEventListener('foo', function(event) {\r\n    self.something();\r\n});\r\n```\r\nShould be written:\r\n```\r\nobj.addEventListener('foo', (event) => {\r\n    this.something();\r\n});\r\n```\r\n\r\n"}}
{"actor":{"display_login":"elsassph"}}