Quasi literal function call syntax
Aron Homberg
info at aron-homberg.de
Sun Sep 23 14:51:57 PDT 2012
Ahmn, yeah - missed the mails in between, to be precise:
Sounds great.
Just an idea to extend your idea a little bit, combining with mine:
What if `whatever ${test} foo` would just construct an object of Template?
The Template object prototype could look lile this:
// In ES harmony syntax :)
Template.prototype = {
toString() {...},
getParts() {...},
getValues() {...},
...
}
etc. pp.
This would normally lead to an implicit string conversion (toString())
where it's needed e.g. if you do something like that:
whatever.innerHTML = `foo {$bar}`;
And you can use the full power of Templates when calling a function in
standard way: safehtml(`foo ${bar}`) where the first argument would be an
object representing the Template prototype + Template value initialized by
the constructor.
Or you could construct a Template like this: new Template('foo ${bar}'); or
Template('foo ${bar}')
This way Template's would be straight forward to use and can be implemented
without any additional grammar magic.
It would also lead to a late/delayed binding / rendering of the template -
if toString() is called, not when the Template object is created which may
be useful for performance too.
What do you think?
Thanks and regards,
Aron
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120923/c8c302ea/attachment.html>
More information about the es-discuss
mailing list