{"comment":{"url":"https://api.github.com/repos/KidSysco/jquery-ui-month-picker/comments/17378569","html_url":"https://github.com/KidSysco/jquery-ui-month-picker/commit/696fc7765fa0b8ac6dcbe2943ee5486559e7f3b6#commitcomment-17378569","id":17378569,"user":{"login":"benjamin-albert","id":5201428,"avatar_url":"https://avatars.githubusercontent.com/u/5201428?v=3","gravatar_id":"","url":"https://api.github.com/users/benjamin-albert","html_url":"https://github.com/benjamin-albert","followers_url":"https://api.github.com/users/benjamin-albert/followers","following_url":"https://api.github.com/users/benjamin-albert/following{/other_user}","gists_url":"https://api.github.com/users/benjamin-albert/gists{/gist_id}","starred_url":"https://api.github.com/users/benjamin-albert/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benjamin-albert/subscriptions","organizations_url":"https://api.github.com/users/benjamin-albert/orgs","repos_url":"https://api.github.com/users/benjamin-albert/repos","events_url":"https://api.github.com/users/benjamin-albert/events{/privacy}","received_events_url":"https://api.github.com/users/benjamin-albert/received_events","type":"User","site_admin":false},"position":null,"line":null,"path":"","commit_id":"696fc7765fa0b8ac6dcbe2943ee5486559e7f3b6","created_at":"2016-05-06T11:41:30Z","updated_at":"2016-05-06T11:41:30Z","body":"I only recently (about 8 months ago) learned that if a property is not found on the global object (know as window in the browser) it searches for an element with  that ID on the `document` (DOM).\r\n\r\nBut there's a reason you rarely see this (in fact I would never use this in an environment that I don't 100% control).\r\n\r\nThe reasons you should avoid using this is:\r\n\r\n1. If you define an element with the Id `foo` and then some in the future defines a global called `foo` you will have a name clash (where the global wins and your code breaks).\r\n\r\n2. Even developers that know this trick will think it's a property on the global object and try to search for its definition in `.js` files before they realize it's defined in HTML.\r\n\r\n3. The Id must be a valid JavaScript identifier (which is rarely the case because you can use characters such as `#` and `.`) \r\n\r\nThe reasons I use this trick in our unit tests are:\r\n1. I'm kind of lazy when it comes to writing good well factored unit tests.\r\n2. I 100% control the test environment so I when this fails I can just refactor this.\r\n3. Unlike a production like environment the whole point of unit tests are running tests and watching it fail (even on annoying things like this).\r\n\r\nI'm not saying it's always a bad idea to use this trick but you should definitely think twice before you use it.\r\n"}}