Skip to content

Instantly share code, notes, and snippets.

@monomon
monomon / String.prototype.template.js
Created October 3, 2015 00:14 — forked from WebReflection/String.prototype.template.js
ES6 Template like strings in ES3 compatible syntax.
// accepts optional transformer
// now transformers are compatible with ES6
String.prototype.template = function (fn, object) {'use strict';
// Andrea Giammarchi - WTFPL License
var
hasTransformer = typeof fn === 'function',
stringify = JSON.stringify,
re = /\$\{([\S\s]*?)\}/g,
strings = [],
values = hasTransformer ? [] : strings,