Skip to content

Instantly share code, notes, and snippets.

@dschnare
Last active May 26, 2016 18:01
Show Gist options
  • Save dschnare/3886395 to your computer and use it in GitHub Desktop.
Save dschnare/3886395 to your computer and use it in GitHub Desktop.
Ruby-style string interpolation for JavaScript.
// Author: Darren Schnare
// Keywords: javascript,interpolation,string,ruby
// License: MIT ( http://www.opensource.org/licenses/mit-license.php )
// Repo: https://gist.github.com/gists/3886395
String.prototype.interpolate = function (o) {
return this.replace(/#\{(.+?)\}/g, function ($0, $1) {
with (o) {
return eval($1);
}
});
}
@dschnare
Copy link
Author

Ah, forget I asked. Just noticed your fork. Thanks for the work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment