/ Published in: JavaScript
"The {adjective} {color} {animal} jumps".template({adjective: 'quick',color: 'brown', animal: 'fox'}) ==> "The quick brown fox"
Expand |
Embed | Plain Text
String.prototype.template = function (o){ return this.replace(/{([^{}]*)}/g, function (a, b) { var r = o[b]; return typeof r === 'string' || typeof r === 'number' ? r : a; } ); }
You need to login to post a comment.
