Это сводит меня с ума. По-моему, я задал этот один и тот же вопрос, но больше не могу его найти (я использовал Stack Поиск переполнения, Google Поиск, вручную просмотрел мои сообщения и искал мой код).
Мне нужно что-то, что было бы похоже на С# String.Format, где вы могли бы сделать что-то вроде
string format = String.Format("Hi {0}",name);
для JavaScript, конечно, и один человек дал мне простой ответ: он не был похож на плагин jQuery или что-то еще, но я думаю, что вы сделали кое-что JSON или что-то в этом роде, и он работал и был прост в использовании.
Я за жизнь меня не могу найти этот пост.
У меня есть это в моем коде, но я не могу найти ничего, что его использует, и я уверен, что использовал его пару раз:
String.prototype.format = function(o)
{
return this.replace(/{([^{}]*)}/g,
function(a, b)
{
var r = o[b];
return typeof r === 'string' ? r : a;
}
);
};