Skip to content

Instantly share code, notes, and snippets.

@micmath
Created October 31, 2011 23:28
Show Gist options
  • Save micmath/1329394 to your computer and use it in GitHub Desktop.
Save micmath/1329394 to your computer and use it in GitHub Desktop.
Ways of documenting inner symbols inside anonymous functions that later get promoted to global
// Be explicit - provide names for everything.
(function(window) {
/**
* The ToolBox
*
* @class ToolBox
*/
var ToolBox = {};
/**
* The module
*
* @namespace ToolBox.Module
*/
ToolBox.Module =
{
/**
* Third tool
* @method ToolBox.Module.tool
* @return {string} The hello message
*/
tool: function()
{
return "Hello World";
}
};
// Expose ToolBox
window.ToolBox = ToolBox;
})(window);
// Be obvious - format your code in a way that is friendly to static analysis
(function(window) {
/**
* The ToolBox
*
* @namespace
* @global
*/
var ToolBox = {
/**
* The module
*
* @namespace
*/
Module: {
/**
* The tool
*
* @return {string} The hello message
*/
tool: function()
{
return "Hello World";
}
}
};
// Expose ToolBox
window.ToolBox = ToolBox;
})(window);
// Be a wizard - use obscure JSDoc 3 tags to say what you mean
(function(window) {
/**
* The ToolBox
*
* @namespace
* @global
*/
var ToolBox = {};
/**
* The module
*
* @namespace
* @alias Module
* @memberof Toolbox
*/
ToolBox.Module =
{
/**
* The tool
*
* @return {string} The hello message
*/
tool: function()
{
return "Hello World";
}
};
// Expose ToolBox
window.ToolBox = ToolBox;
})(window);
// Be blunt - document everything inside the anonymous function as global
(/** @alias <global> */function(window) {
/**
* The ToolBox
*
* @namespace
*/
var ToolBox = {};
/**
* The module
*
* @namespace
*/
ToolBox.Module =
{
/**
* The tool
*
* @return {string} The hello message
*/
tool: function()
{
return "Hello World";
}
};
// Expose ToolBox
window.ToolBox = ToolBox;
})(window);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment