Skip to content

Instantly share code, notes, and snippets.

@whalesalad
Created August 8, 2009 01:42
Show Gist options
  • Select an option

  • Save whalesalad/164274 to your computer and use it in GitHub Desktop.

Select an option

Save whalesalad/164274 to your computer and use it in GitHub Desktop.
// Screwing around with string interpolation
String.prototype.inter = function(r) {
return this.replace(/\{([^}]+)\}/g, function() {
return r[arguments[1]];
});
}
$(document).ready(function() {
var string = 'There are {num_kids} kids in the {room_name}.';
alert(string.inter({
num_kids: 42,
room_name: 'living room'
}));
});
// Will alert "There are 42 kids in the living room.";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment