The ability to reply to discussions is limited to PRO members. Want to join in the discussion? Click here to subscribe now.

Use Template Literals in ES6

Use Template Literals in ES6

4:12
ECMAscript 6 lets us use string templates to gain a lot more control over strings in JavaScript.
Watch this lesson now
Avatar
egghead.io

ECMAscript 6 lets us use string templates to gain a lot more control over strings in JavaScript.

Avatar
Bharat

Question,
What is the current adoption status of ECMAscript 6 both on the client side (browser vendors) and server side (node or is there any other server-side Javascript technologies that are worth considering)?
Seems to me that it is ushering in revolutionary changes in how Javascript works and makes is a respectable language, e.g., Ruby.
Please provide some practical advice.
Thanks.
Bharat

In reply to egghead.io
Avatar
Sidhartha

This doesn't work in traceur and throws a ModuleEvaluationError: Object # has no method 'setProperty'

In reply to egghead.io
Avatar
Alan

Probably worth mentioning that a template handler doesn't have to return a string. It can return any JavaScript value. So you can use template handlers to implement custom DSLs to describe arbitrary structures. At ArangoDB we use a template handler for the query language to make it easier to add bound parameters to a query: https://github.com/arangodb/arangojs/blob/master/src/aql-query.js

Avatar
Gene

Not a criticism of the lesson but a comment on the code
function
tag(strings, ...values){
The
code that produces is hard to read maintain. The template syntax is great referring to variables by name. Nice and readable. But then using the tag function to manipulate the strings where positional arguments are inferred or hidden behind the runtime output leads to maintainability errors. I wonder if there is a better example of using the tag type syntax.

Avatar
Alberto Díaz

I got this error, any idea?

function tag(strings, ...values){
^^^

SyntaxError: Unexpected token ...
at exports.runInThisContext (vm.js:53:16)
at Module.compile (module.js:373:25)
at Object.Module.
extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)
at startup (node.js:139:18)
at node.js:968:3

HEY, QUICK QUESTION!
Joel's Head
Why are we asking?