Skip to content

Instantly share code, notes, and snippets.

@kflorence
Last active December 10, 2015 10:58
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 kflorence/4424069 to your computer and use it in GitHub Desktop.
Save kflorence/4424069 to your computer and use it in GitHub Desktop.
A simple function for namespacing things like events and class names
// namespacer( "kf", [ "one", "two" ] );
// => { one: "one.kf", two: "two.kf" }
function namespacer( namespace, items, separator, before ) {
var i, item,
l = items.length,
namespaced = {};
if ( l && namespace ) {
if ( !separator ) {
separator = ".";
}
for ( i = 0; i < l; i++ ) {
item = items[ i ];
namespaced[ item ] = before ?
namespace + separator + item :
item + separator + namespace;
}
}
return namespaced;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment