用es5实现模板字符串
时间:2019-11-25 16:46:40
收藏:0
阅读:349
废话不多说,主要是利用正则表达式replace+eval动态取值(纯属娱乐)
String.prototype.myReplace = function(){
return this.replace(/\$\{([^}]*)\}/g,function(metched,key){
return eval(key)
})
}
var name = '张三',age = '20';
var userTxt = '${name}今年${age}岁了'
)
原文:https://www.cnblogs.com/angfl/p/11928292.html
评论(0)