Javascript String parameterize(parameters)

Description

Javascript String parameterize(parameters)


var Routes = {//from ww w  .  j  a v a2s. c o  m
 url: function(name, parameters) {
  var pattern = Routes.get(name);
  if (parameters == null) {
   parameters = {};
  }
  
  return pattern.parameterize(parameters);
 },
 
 get: function(name) {
  return Routes.NAMED_ROUTES[name];
 }
};
String.prototype.parameterize = function(parameters) {
 var result = this;
 for (var name in parameters) {
  result = result.replace('${' + name + '}', parameters[name]);
 }
 return result;
};
Routes.NAMED_ROUTES =



PreviousNext

Related