Lexx,
<body>
<script>
function Templater() {
let str = '';
let tags = {
getFullName(tagSpan, up = '') {
return tagSpan.length ? tagSpan.map(a => `${a}${up}`).join(' ') : '';
},
span(...tagSpan) {
str += `<span>${this.getFullName(tagSpan, '!!!')}</span>`
return this;
},
p(...tagSpan) {
str += `<p>${this.getFullName(tagSpan)}</p>`
return this;
},
toString() {
return str
}
};
return tags;
}
const template = Templater().p(
Templater().span('Hello'),
Templater().span('World')
)
document.body.append(template);
const temp = Templater().p(
Templater().span('test').span('span')
).toString();
document.write('<br>')
document.body.append(temp);
</script>
</body>