Last active
May 26, 2016 18:01
-
-
Save dschnare/3886395 to your computer and use it in GitHub Desktop.
Ruby-style string interpolation for JavaScript.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ah, forget I asked. Just noticed your fork. Thanks for the work!