Skip to content

Instantly share code, notes, and snippets.

@johnhunter
Created August 28, 2011 14:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnhunter/1176741 to your computer and use it in GitHub Desktop.
Save johnhunter/1176741 to your computer and use it in GitHub Desktop.
TextMate snippets for JS modules
/*
Module $1
${7:Description of $1.}
@author ${TM_FULLNAME}
created `date +%Y-%m-%d`
*/
var ${1:module} = (function (${2:\$}) {
var ${5:bar};
${4:function foo () { return bar; \}
/*
Note:
- private members are locally scoped vars / functions
- public members are exported in the return object
- jQuery imported as $ (remove if not required)
*/
}
return {
${6:foo: foo}
};
}(${3:jQuery}));
/*
Module $1 augments $2
${6:Description of $1.}
@author ${TM_FULLNAME}
created `date +%Y-%m-%d`
*/
(function (global${4:, \$}) {
var our, // ref to namespace '$2'
my; // ref to submodule '$1'
// create namespace if it doesn't exist
our = global.${2:namespace} = global.$2 || {};
our.${1:submodule} = my = {};
${5:/*
Note:
- private members are locally scoped vars / functions
- public members are be properties of 'my' (e.g. my.foo)
- global is a ref to the global context (typically window)
- jQuery imported as \$ (remove if not required)
*/
my.foo = 'foo';
}
}(window${3:, jQuery}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment