{"action":"created","issue":{"url":"https://api.github.com/repos/ResultadosDigitais/javascript-style-guide/issues/1","repository_url":"https://api.github.com/repos/ResultadosDigitais/javascript-style-guide","labels_url":"https://api.github.com/repos/ResultadosDigitais/javascript-style-guide/issues/1/labels{/name}","comments_url":"https://api.github.com/repos/ResultadosDigitais/javascript-style-guide/issues/1/comments","events_url":"https://api.github.com/repos/ResultadosDigitais/javascript-style-guide/issues/1/events","html_url":"https://github.com/ResultadosDigitais/javascript-style-guide/pull/1","id":158450396,"number":1,"title":"good practices to attach events with jQuery","user":{"login":"pedrohenriquerls","id":952303,"avatar_url":"https://avatars.githubusercontent.com/u/952303?v=3","gravatar_id":"","url":"https://api.github.com/users/pedrohenriquerls","html_url":"https://github.com/pedrohenriquerls","followers_url":"https://api.github.com/users/pedrohenriquerls/followers","following_url":"https://api.github.com/users/pedrohenriquerls/following{/other_user}","gists_url":"https://api.github.com/users/pedrohenriquerls/gists{/gist_id}","starred_url":"https://api.github.com/users/pedrohenriquerls/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pedrohenriquerls/subscriptions","organizations_url":"https://api.github.com/users/pedrohenriquerls/orgs","repos_url":"https://api.github.com/users/pedrohenriquerls/repos","events_url":"https://api.github.com/users/pedrohenriquerls/events{/privacy}","received_events_url":"https://api.github.com/users/pedrohenriquerls/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-06-03T20:40:49Z","updated_at":"2016-06-06T12:07:00Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/ResultadosDigitais/javascript-style-guide/pulls/1","html_url":"https://github.com/ResultadosDigitais/javascript-style-guide/pull/1","diff_url":"https://github.com/ResultadosDigitais/javascript-style-guide/pull/1.diff","patch_url":"https://github.com/ResultadosDigitais/javascript-style-guide/pull/1.patch"},"body":"The idea is avoid chain the .off and .on, when you will attach some event anywhere.\r\n### Why not do it\r\nThe jQuery use a events queue to know what is the callback he will call, when you use off first(to avoid assign the same event more than one time), this event go to end of queue, so imagine this scenario...\r\n```html\r\n<div class=\"blastoise\">\r\n  <button class=\"ok-btn\"></button>\r\n</div>\r\n```\r\n```javascript\r\n// Bad case: if you click on ok-btn, the parent will respond the event first\r\n$('.ok-btn').off().on('click', function() {console.log('click! click!!')});\r\n$('.blastoise').on('click', function() {console.log('parent!!')});\r\n\r\n// Good: In this case the ok-btn will execute exactly the right callback and avoid any other callback\r\n$('.ok-btn').on('click', function(e) {\r\n  e.stopPropagation();\r\n  console.log('click! click!!');\r\n})\r\n$('.blastoise').on('click', function(){console.log('parent!!')});\r\n```"},"comment":{"url":"https://api.github.com/repos/ResultadosDigitais/javascript-style-guide/issues/comments/223940472","html_url":"https://github.com/ResultadosDigitais/javascript-style-guide/pull/1#issuecomment-223940472","issue_url":"https://api.github.com/repos/ResultadosDigitais/javascript-style-guide/issues/1","id":223940472,"user":{"login":"lucasalencar","id":366659,"avatar_url":"https://avatars.githubusercontent.com/u/366659?v=3","gravatar_id":"","url":"https://api.github.com/users/lucasalencar","html_url":"https://github.com/lucasalencar","followers_url":"https://api.github.com/users/lucasalencar/followers","following_url":"https://api.github.com/users/lucasalencar/following{/other_user}","gists_url":"https://api.github.com/users/lucasalencar/gists{/gist_id}","starred_url":"https://api.github.com/users/lucasalencar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lucasalencar/subscriptions","organizations_url":"https://api.github.com/users/lucasalencar/orgs","repos_url":"https://api.github.com/users/lucasalencar/repos","events_url":"https://api.github.com/users/lucasalencar/events{/privacy}","received_events_url":"https://api.github.com/users/lucasalencar/received_events","type":"User","site_admin":false},"created_at":"2016-06-06T12:07:00Z","updated_at":"2016-06-06T12:07:00Z","body":"For me its awesome! :shipit: "}}
{"actor":{"display_login":"lucasalencar"}}