Skip to content

Instantly share code, notes, and snippets.

@joshbedo
Created May 15, 2014 23:43
Show Gist options
  • Save joshbedo/11b1c5097590c1a0ed3b to your computer and use it in GitHub Desktop.
Save joshbedo/11b1c5097590c1a0ed3b to your computer and use it in GitHub Desktop.
Backbone collection url() snippet
test = {
urlRoot: "http://google.com",
url: function(options) {
var path;
if(options && options.param && options.query) {
path = "?" + options.param + "=" + options.query;
}
return (path) ? this.urlRoot + path : this.urlRoot;
}
}
console.log(test.url());
console.log(test.url({ param: "keyword", query: "test"}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment