The new javascript template syntax is great. Super readable and powerful. I\'d like to start using it.
I tried this template:
function addGalleryItem(ima
Generally you can use eval
to assert if the browser supports certain syntax changes:
var isTemplateSupported = true;
try {
eval("``");
}
catch(e) {
isTemplateSupported = false;
}
console.log("Supports Template Literals", isTemplateSupported);
So for your implementation:
var template;
try {
template = eval("``".....);
}
catch(e) {
if(e instanceof SyntaxError) {
template = '' + ...
}
}
But it's much easier to use a transpiler because it would be tedious to support two implementations every time you need a literal.