Created
March 22, 2014 15:12
-
-
Save devinrhode2/9708720 to your computer and use it in GitHub Desktop.
fe fi fo fum fam for the shenanigans
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
<script src="lodash.custom.min.js"></script> | |
<script type="text/javascript"> | |
/* | |
Example: | |
_({key: value}).join('=', ';') === 'key=value;' | |
*/ | |
(function(){ | |
var oldJoin = _.prototype.join; | |
_.prototype.join = function (colon, comma) { | |
if ( comma ) { | |
var result = ''; | |
_(this).forOwn(function(key, value) { | |
result += key + colon + value + comma; | |
}); | |
//remove last comma | |
return result.substring(0, result.length - comma.length); | |
} else if (_.isFunction(oldJoin)) { | |
return oldJoin.apply( | |
this, | |
Array.prototype.slice.call(arguments, 0) | |
); | |
} else { | |
throw new Error('Please pass in a second argument'); | |
} | |
}; | |
/* | |
Example: | |
'http://domain.com/page?' + _.querystring({apples: '1.5', oranges: '2'}) | |
'http://domain.com/page?' + 'apples=1.5&oranges=2' | |
*/ | |
_.querystring = function(hash) { | |
return _(hash).join('=', '&'); | |
}; | |
})(); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment