I prefer to the under style:
var templateManager = (function () {
    var templates = {};

    function supplant(str, params){
        for (var prop in params) {
            str = str.split('{' + prop + '}').join(params[prop]);
        }
        return str;
    }

    return {
        render: function (name, params) {
            if (typeof templates[name] !== 'string') {
                throw 'Template ' + name + ' not found!';
            }
            return supplant(templates[name], params);
        },
        defineTemplate: function (name, template) {
            templates[name] = template;
        }
    };
})();

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to