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