Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
String.substitute and example used on the uk.thebar.com
String.prototype.substitute = function (object) {
return this.replace(/\{(.+?)\}/g, function (match, name) {
return name in object ? object[name] : match;
});
};
var query = this.options.queryUrl.substitute({
spirits: this.element.find('.ingredients-list-spirits .is-selected').map(function() {
return $(this).data('value');
}).get().join(),
mixers: this.element.find('.ingredients-list-mixers .is-selected').map(function() {
return $(this).data('value');
}).get().join(),
garnishes: this.element.find('.ingredients-list-garnishes .is-selected').map(function() {
return $(this).data('value');
}).get().join()
});
$(this).attr('href',query.substitute({ type : $(this).attr('data-type') }));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment