Super fast js templating library

ref: http://jsperf.com/string-format-underscore-vs-hot

var template = {};
template.format = function(string, context){
    return string.replace(/\{(\S+)\}/g), function(str, key){ return context[key]; });
};
// using
// template.format(“{x}”, { x: 1 });
// template.format(“{x}, {y}”, { x: 1, y: 2 });

but it will only supported “replace variable”
no more condition or loop in template string :p

useful for simple replace variable

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s