{"id":1147,"date":"2015-07-21T16:52:54","date_gmt":"2015-07-21T14:52:54","guid":{"rendered":"http:\/\/www.speich.net\/articles\/?p=1147"},"modified":"2019-10-06T10:08:03","modified_gmt":"2019-10-06T08:08:03","slug":"javascript-tip-shorten-document-getelementbyid-in-one-line","status":"publish","type":"post","link":"https:\/\/www.speich.net\/articles\/en\/2015\/07\/21\/javascript-tip-shorten-document-getelementbyid-in-one-line\/","title":{"rendered":"JavaScript tip: Shorten document.getElementById with Function.prototype.bind"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">I found this really nice one liner on&nbsp;Nick Desaulniers blog about <a href=\"https:\/\/nickdesaulniers.github.io\/blog\/2013\/09\/26\/function-dot-prototype-dot-bind-edge-cases\/#disqus_thread\">Function.prototype.bind Edge Cases<\/a>:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code class=\"language-javascript\">\/\/ var byId = function(id) { return document.getElementById(id); }\nvar byId = document.getElementById.bind(document);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Love it!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I found this really nice one liner on&nbsp;Nick Desaulniers blog about Function.prototype.bind Edge Cases: \/\/ var byId = function(id) { return document.getElementById(id); } var byId = document.getElementById.bind(document); Love it!<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-1147","post","type-post","status-publish","format-standard","hentry","category-javascript","entry"],"_links":{"self":[{"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/posts\/1147","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/comments?post=1147"}],"version-history":[{"count":2,"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/posts\/1147\/revisions"}],"predecessor-version":[{"id":1660,"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/posts\/1147\/revisions\/1660"}],"wp:attachment":[{"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/media?parent=1147"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/categories?post=1147"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/tags?post=1147"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}