Please activate JavaScript!
Please install Adobe Flash Player, click here for download

SAE Magazine

120 1 - Protect your code. The first thing to start with is considering the environment jQuery plugins are usually used in. Most of the time you’ll see parts of the HTML document looking similar to this: At the end of day, all of these will end up com- pressed and stuffed into one file. Besided, any plugin should be available in a pre-minified version. So, what may cause issues? Imagine someplugin2.js is a poorly developed plugin and defines anything in the global name- space, meaning the window object. Chances are pretty great that something will break. How can we prevent this? The answer is pretty sim your code into a so-c invoking function. As we their variables for thems following is considered most of your scripts with: // File: 02-anonymous-sel (function(){ // code goes here })(); We create an anonymou braces and call that group Now let’s test out the n want to keep everything t private. As JavaScript isn we’ll just use the anonym space. // File: 03-namespace.js var global = ‘i am global’; console.log(window.globa (function(){ // global is available he var local = ‘i am local’; })(); console.log(window.local) PRODUCTION & KNOW HOW // DEVELOPING JQUERY PLUGINS THE RIGHT WAY Developing jQuery Plugins

Pages