JavaScript tip: Shorten document.getElementById with Function.prototype.bind

I found this really nice one liner on 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!

Leave a comment

Your email address will not be published. Required fields are marked *