Last active
December 10, 2015 10:58
-
-
Save kflorence/4424069 to your computer and use it in GitHub Desktop.
A simple function for namespacing things like events and class names
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
// 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