boxmein

Javascript ruby-like string extrapolation

Mar 12th, 2014
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // extrapolate.js
  2. String.prototype.extrapolate = function() {
  3.   var str = this;
  4.   this.match(/#\{(.+?)\}/g).forEach(function(each) {
  5.     str = str.replace(each, eval(each.slice(2, -1)));
  6.   });
  7.   return str.valueOf();
  8. };
Advertisement
Add Comment
Please, Sign In to add comment