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>
未完待定

浙公网安备 33010602011771号