This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Simple way to embed html in javasript | |
Array.prototype.joinHtml = function () { | |
return this.join(''); | |
}; | |
String.prototype.supplant = function (o) { | |
return this.replace(/{([^{}]*)}/g, | |
function (a, b) { | |
var r = o[b]; | |
return typeof r === 'string' || typeof r === 'number' ? r : a; | |
} | |
); | |
}; | |
var html = [ | |
'<div class="{classes}">', | |
'<p>{text}</p>', | |
'</div>', | |
].joinHtml().supplant({ | |
classes: "class1", | |
text: "dummy text" | |
}); | |
console.log(html); // output: <div class="class1"><p>dummy text</p></div> |
No comments :
Post a Comment