Edit in JSFiddle

    /*** Setup ***/
    
    GuruStop = {}; // define a namespace placeholder object
    GuruStop.String = { // define a sub namespace / class as an object
        // We define our method as a member of the object which defines our class.
        // This is just one way to do it in JavaScript
        format: function(text) { // in JavaScript you can pass any number of arguments to any function
            // We access all arguments passed to the functions (explicit and implicit) via 'arguments'
            if (!text) return text; // if string is null or undefined or empty, just return it
            // if it's not a string, this call will fail. We won't worry about that. Let it fail if it's not!
            for (var i = 1; i < arguments.length; i++) { // exclude first argument 'text' and start at 1
                
                // The reason we use regex is that JavaScript "replace" method when passed (string, string)
                // does replace only one occurance of the first string, what if {0} existed twice in template?
                // Regex, with "g" as option, applies a search in string for all occurances. So we use that
                var pattern = new RegExp("\\{" + (i - 1) + "\\}", "g"); // remember 'i' starts at 1 not 0
                
                text = text.replace(pattern, arguments[i]);
            }
            return text;
        }
    };
    
    /*** Usage ***/

    // We define a function that calls itself, 
    // so that all variable names we use etc are local
    // If jQuery used in the page, use $(function() { ... }); instead
    (function() { 
        // We could have used jQuery, but this is not purpose or needed
        var templateContainer = document.getElementById("template-container");
        var template = templateContainer.innerHTML;
        var name = "my friend"; // param 0
        var site = "GuruStop.NET" // param 1
            
        var result = GuruStop.String.format(template, name, site);
        
        templateContainer.innerHTML = result;
    }) ();
<div id="template-container">
    Hi {0},<br />
    Welcome to {1}.
</div>