JavaScript

How to ensure that duplicate JavaScript doesn’t run twice?

This often happens when your customers are using more than one plugin/addons both requiring the same JavaScript. You can avoid the execution of both of them by using the following trick. if(window.MyCustomNameSpace === true){ return false; } window.MyCustomNameSpace = true Why it works? The idea here is to set a namespace as soon as you […]

Why do you need a self-invoking function in JavaScript?

What is a Self-Invoking function? A self-invoking function is called immediately after definition. For example look at the following codes: [code lang=”javascript”] (function(){ // Called as soon as inserted console.log(“I am running”); })(); [/code] Why do you need a self-invoking function? A self-invoking function is an anonymous function and thus all the variables defined inside […]

Scroll to top