Created
August 28, 2011 14:35
-
-
Save johnhunter/1176741 to your computer and use it in GitHub Desktop.
TextMate snippets for JS modules
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
/* | |
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