function getType(obj) {
let type = typeof obj;
if (type !== "object") {
return type;
}
return Object.prototype.toString.call(obj).replace(/^\[object (\S+)\]$/, '$1');
}
console.log(getType({ name: 'wxq' }))
var str = 'aaa bbb ccc';
uw = str.replace(/\b\w+\b/g, function (word, index) {
console.log(word)
console.log('uw'+index)
return word.substring(0, 1).toUpperCase() + word.substring(1);
}
);
console.log(uw)
var ary = ["一", "二", "三", "四", "五", "六"]
"123456".replace(/\d/g, function (val,index) {
console.log('ary'+index)
return ary[val - 1]
})
var obj = {
name: 'leaf',
age: 20
}
var str = "我是{{name}},name是我的名字,我今年{{age}}岁";
function render(template, context) {
template.replace(/\{\{(.*?)\}\}/g, (match, key) => {
console.log(match)
console.log(key)
context[key.trim()]
})
return template.replace(/\{\{(.*?)\}\}/g, (match, key) => context[key.trim()]);
}
console.log(render(str, obj))
console