1. function easyTpl(tpl, data){
    2. var re = /{{([a-zA-Z$_][a-zA-Z$_0-9\.]*)}}/g;
    3. return tpl.replace(re, function(raw, key, offset, string){
    4. var paths = key.split('.'),
    5. lookup = data;
    6. while(paths.length>0){
    7. lookup = lookup[paths.shift()];
    8. }
    9. return lookup||raw;
    10. });
    11. }
    12. var data = {
    13. name: 'rashomon',
    14. dog: {
    15. color: 'yellow',
    16. age: 2
    17. }
    18. };
    19. var tpl = 'Hello, my name is {{name}}. I have a {{dog.age}} year old {{dog.color}} dog.';
    20. console.log(easyTpl(tpl, data));