I think ES6 is more awesome than people usually realize. Oh by the way, here is some sugar:
 
    var template = compile`Hello, ${"name"}!`
    console.log(template({ name: "world" }))
 
 
 
Of course, ES6 does not have a compile function built-in, but I surely have one:
 
    function compile(strs, ...args) {
      return function(object) {
        var chunks = []
        for (var i=0; i<strs.length-1; i++) {
          chunks.push(strs[i])
          chunks.push(object[args[i]])
        }
        chunks.push(strs[i])
        return chunks.join('')
      }
    }
 
 
 
16.12.2014, 20:03, "Claude Pache" <[email protected]>:

Le 16 déc. 2014 à 16:42, Matthew Robb <[email protected]> a écrit :

Actually, it would be cool if some sugar could be done for the example I just did:
 
var template = compile`
Hello ${{first_name}}
`;
 
template({ first_name: "John" });
 
 
I guess you want sugar for the following valid ES6 code?
 
 
```_javascript_
 
var template = _ => `
Hello ${_.first_name}
`;
 
template({ first_name: "John" });
 
```
 
—Claude
 
,

_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to