Skip to content

Instantly share code, notes, and snippets.

@damienklinnert
Created October 25, 2012 12:21
Show Gist options
  • Save damienklinnert/3952282 to your computer and use it in GitHub Desktop.
Save damienklinnert/3952282 to your computer and use it in GitHub Desktop.
(function () {
// this is the most important method. It creates a function
// that uses either jQuery.ajax or node request() to do
// async requests to the web.
//
// ThIS METHOD CREATES A FUNCTION DEPENDING ON THE ENVIRONMENT.
// AFTER INITIALIZING EVERYTHINGZZ AMAZZIN' FAST!!!111einself
var setupRequest = function (environment) {
var request = null;
if (environment === 'node') {
// load dependencies with require(...);
request = function () {
};
}
if (environment === 'browser') {
// jQuery is already here with name jQuery, dont load it
request = function () {
};
}
// return our request function here
return request;
};
// create objects (export object)
var library = {};
// detect on which environment we are working right now
// load dependencies and create our request method
var request = null;
if (typeof exports !== 'undefined' && module && module.exports) {
request = setupRequest('node');
module.exports = library;
} else {
request = setupRequest('browser');
window.library = library;
}
// usual api stuff, this is only allowed to use request for
// http requests -> some example in here
var publicMethod = library.publicMethod = function () {
// this is an example function which is exposed to the public
};
var privateMethod = function () {
// this is an example function which is private
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment