Hello world!

js模板引擎

最初想法是这样子

 1 String.prototype.substitute = function(object){
 2     return this.replace(/\$\{([^{}]+)\}/gm, function(match, attr){
 3         if (object && object[attr] !== void 0)
 4             return  object[attr];
 5         return  '';
 6     });                
 7 }
 8 var str = '<li>${age}</li><li>${name}</li>';
 9 console.log(str.substitute({
10     "name":'hello',
11     "age": 24
12 }));

输出:
<li>24</li><li>hello</li>

 

未完待定

posted @ 2016-10-13 20:24  oOo泡果奶  阅读(104)  评论(0)    收藏  举报