That code is actually from here:
http://stackoverflow.com/questions/6104 ... ing-formatIt's a JavaScript implementation of something like string.Format which exists in C#. It makes it easier to interpolate strings. For example, if I wanted to greet somebody by their first and last name, and tell them their age, normally I would have to do something like this...
var greeting = "Hello " + firstName + " " + lastName + ", you are " + age + ".";
By adding this "format" function to strings, I can do it like this:
var greeting = "Hello {0} {1}, you are {2}".format(firstName, lastName, age);
The way it works is: the variable "args" is an array of all arguments passed to the format function. So in the example above, the array is [firstName, lastName, age]. Then it calls this.replace with a regular expression that finds digits inside braces. It runs a function for every occurrence, and this function pulls the relevant value out of the arguments array.
The latest version of JavaScript allows for template strings (
http://tc39wiki.calculist.org/es6/template-strings/), so in the future we'll be able to do this easily without having to create our own format function.