code_junkie

How do you store request URL's in Javascript to satisfy the DRY principal?

Nov 11th, 2011
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. NAMESPACE.categories.baseUri = '/categories';
  2. NAMESPACE.categories.getUri = function(options)
  3. {
  4. options = options || {};
  5. var uri = [NAMESPACE.categories.baseUri];
  6.  
  7. if(options.id)
  8. {
  9. uri.push(options.id);
  10. }
  11. if(options.action)
  12. {
  13. uri.push(options.action);
  14. }
  15. if(options.format)
  16. {
  17. uri.push('?format=' + options.format);
  18. }
  19.  
  20. return uri.join('/');
  21. }
  22.  
  23. function ControlValuePair(Id, Value)
  24. {
  25. this.Id = Id;
  26. this.Value = Value;
  27. }
  28.  
  29. function CreateCollection(ClassName)
  30. {
  31. var obj=new Array();
  32. eval("var t=new "+ClassName+"()");
  33. for(_item in t)
  34. {
  35. eval("obj."+_item+"=t."+_item);
  36. }
  37. return obj;
  38. }
  39.  
  40. function ValuePairsCollection()
  41. {
  42. this.Container="";
  43. this.Add=function(obj)
  44. {
  45. this.push(obj);
  46. }
  47. }
Add Comment
Please, Sign In to add comment