/ Published in: JavaScript
                    
                                        http://stackoverflow.com/questions/3628649/javascript-self-contained-sandbox-events-and-client-side-stack
                
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
 (function(global) { var Sandbox = function(modules, callback) { if (!(this instanceof Sandbox)) { return new Sandbox(modules, callback); } // modules is an array in this instance: for (var i = 0, len = modules.length; i < len; i++) { installedModules[modules[i]](this); } callback(this); }; Sandbox.modules = {}; global.Sandbox = Sandbox; })(this); // Example module: // You extend the current sandbox instance with new functions Sandbox.modules.ajax = function(sandbox) { sandbox.ajax = $.ajax; sandbox.json = $.getJSON; }; // Example of running your code in the sandbox on some page: Sandbox(['ajax'], function(sandbox) { sandbox.ajax({ type: 'post', url: '/Sample/Url', success: function(response) { // success code here. remember this ajax maps back to $.ajax } }); });
Comments
                    Subscribe to comments
                
                