ES6 Template like strings in ES3 compatible syntax.
// this is now a module: | |
// https://github.com/WebReflection/backtick-template#es2015-backticks-for-es3-engines-- | |
var template = require('backtick-template'); | |
// just string | |
const info = 'template'; | |
`some ${info}` === template('some ${info}', {info}); | |
// passing through a transformer | |
transform `some ${info}` === | |
template(transform, 'some ${info}', {info}); | |
// using it as String method | |
String.prototype.template = template.asMethod; | |
`some ${info}` === 'some ${info}'.template({info}); | |
transform `some ${info}` === | |
'some ${info}'.template(transform, {info}); |
This comment has been minimized.
This comment has been minimized.
|
This comment has been minimized.
This comment has been minimized.
fixed, will update the CSP version too soon, cheers |
This comment has been minimized.
This comment has been minimized.
var f = function (_) { return 'foo'; }, v = 1;
`hm ... ${f({a: v})}`
"hm ... foo" "hm ... ${f({a: v})}".template({
f: function () { return 'foo'; },
v: 1
});
... and fixed |
This comment has been minimized.
This comment has been minimized.
+1 for @hooblei - there is bad RE which makes |
This comment has been minimized.
This comment has been minimized.
+1 |
This comment has been minimized.
This comment has been minimized.
Has anyone turned this into a module instead of a prototype extend? |
This comment has been minimized.
This comment has been minimized.
@aMarCruz @hooblei @JaroslavMoravec @ramtob @bcomnes I've rewritten the original idea from scratch and covered 100% (let's say it was an excuse to test coveralls but ... hey ...) https://github.com/WebReflection/backtick-template#es2015-backticks-for-es3-engines-- Best Regards |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
Is this kinda proposal to get rid of ES6 way? Any luck to discuss it with TC39?