The JavaScript NIFE Pattern

Most JavaScript developers are very familiar with the Immediately Invoked Function Expression (IIFE): (function () { var x = ‘loaded’; console.log(x); }()); In this expression, we create a function that wraps all the enclosed code in its scope, and at the end we execute the function with the parentheses. If you aren’t super-careful though, you […]

Cross Domain Iframe Resizing

If you have ever integrated third party components on your website, you will have found a dazzling variety of integration methods, from JavaScript snippets, to iframes, to server-side APIs. Many of the integrations seek to inject content onto your page, but I sincerely advise against this. You don’t need to spend long reading the OWASP […]

Comments Are A Clue

JSDoc comments, like many comments in software, can be a great clue for those who want to refactor their program. Take this common example, variations of which can be found easily online: /** * Check input object is a string * @param {Object} s */ function check(s) { return typeof s === ‘string’; } If […]