Created
May 20, 2014 20:24
-
-
Save mauriciosoares/782695079304ca8ddf6a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Sandbox() { | |
var args = Array.prototype.slice.call(arguments), | |
// last arg is the callback | |
callback = args.pop(), | |
// gets all modules beeing passed as different args, or as an Array | |
modules = (args[0] && typeof args[0] === 'string') ? args : args[0], | |
i; | |
// if its not beeing called as a constructor | |
if(!(this instanceof Sandbox)) { | |
return new Sandbox(modules, callback); | |
} | |
// if no module is passed, or '*' | |
if(!modules || modules[0] === '*') { | |
modules = []; | |
for(i in Sandbox.modules) { | |
modules.push(i); | |
} | |
} | |
// starts all the modules | |
for(i = 0; i < modules.length; i += 1) { | |
Sandbox.modules[modules[i]](this); | |
} | |
// calls the callback | |
callback(this) | |
} | |
Sandbox.modules = {}; | |
Sandbox.modules.dom = function(box) { | |
box.getElement = function() {} | |
} | |
Sandbox.modules.ajax = function(box) { | |
box.request = function() {} | |
} | |
Sandbox.modules.events = function(box) { | |
box.click = function() {} | |
} | |
Sandbox('*', function(box) { | |
console.log(box); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment