Advertisement
lnikod4s

Regex1

Jun 5th, 2015
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. String.prototype.format = function (options) {
  2.     return this.replace(/(?:#{(\w+)})/g, function ($0, $1) {
  3.         return options[$1];
  4.     });
  5. };
  6.  
  7. var options1 = {name: 'John'};
  8. console.log('Hello, there! Are you #{name}?'.format(options1));
  9.  
  10. var options2 = {name: 'John', age: 13};
  11. console.log('My name is #{name} and I am #{age}-years-old'.format(options2));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement