String.format function for javascript (Dot Net style)

I need a string.format function, after googling around for server minutes. I find all existing solutions is like this one in Ray’s blog

for(var i=0;i< arguments.length;i++) {
	var re = new RegExp('\{' + i + '\}','gm');
	str = str.replace(re, arguments[i]);
}
return str;

It’s very short, but there is one problem~
It can’t handle

string.format("{0}", "{0}")

and regexp has poor performance~

So,
let’s do one ourself, and test the highlight.js wp plugin. :D

/*
 *	String.format function
 *	by leen.name
 */

/*
	this function provide you the DotNet style string.format for javascript.
	it will replace {INDEX_OR_NAME} to the value supplied by the agruments, and double braces({{) to single brace({).

	Examples:

	String.format("Hello {0}, It's {1}.", "world", "me")
	// returns
	//	"Hello world, It's me."

	"I prefer {0} better than {1}."
		.format("formatting text using {0}", "%0")
	// returns
	// 	"I prefer formatting text using {0} better than %0."

	String.format(
		"{language}'s string concat operator is '{operator}'.", {
			language: "php",
			operator: "."
		})
	// returns
	// 	"php's string concat operator is '.'."

	"after format, {{0} becames {0}.".format("the value")
	// returns
	// 	"after format, {0} becames the value."

*/
if(!String.prototype.format)
	String.prototype.format = function(){
		var param = arguments.length === 1 && typeof(arguments[0]) == "object" ? arguments[0] : arguments;
		var i = 0, result = "";
		for(var s; (s = this.indexOf("{", i)) !== -1;){
			result += this.slice(i, s);
			if(this[s+1] === "{"){
				i = s + 2;
				result += "{";
				continue;
			}
			var i = this.indexOf("}", s + 1);
			if(i === -1)
				throw "incorrect format: {0}".format(this);
			result += param[this.slice(s + 1, i)];
		}
		return result + this.slice(i);
	}
if(!String.format)
	String.format = function(str){
		return String.prototype.format.apply(str, Array.prototype.slice.call(arguments, 1));
	}