Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- 'My name is #{name=Earl}'.interpolate2(); // "My name is Earl"
- 'My name is #{name}'.interpolate2({ name: 'Earl2D2' }); // "My name is Earl2D2"
- */
- String.prototype.interpolate2 = (function(){
- var re = /#{([-\w]+)(?:=([-\w]+))?}/g;
- return function(source) {
- if (!source) source = { };
- return this.replace(re, function(match, name, value) {
- return (name in source ? source[name] : (value || ''));
- })
- }
- })();
Add Comment
Please, Sign In to add comment