Quasi literal function call syntax
Aron Homberg
info at aron-homberg.de
Sun Sep 23 14:43:52 PDT 2012
2012/9/23 Matthew Robb <matthewwrobb at gmail.com>
> BUT, just putting this out there, I do think it would be great to have a
> Quasi global constructor that could have some static members hanging off of
> it, possibly including a potential parse method, but also some of the more
> likely bundled output:
>
Quasi.escape`my ${unsafe} stuff`
>
>
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 Quasi?
The Quasi object prototype could look lile this:
// In ES harmony syntax :)
Quasi.prototype = {
toString() {...},
getParts() {...},
getValues() {...}
}
etc. pp.
This would normally lead to an implicit string conversion where it's needed
e.g. if you do something like that:
whatever.innerHTML = `foo {$bar}`;
And you can use the full power of Quasis when calling a function in
standard way: safehtml(`foo ${bar}`) where the first argument would be an
object representing the Quasi prototype + Quasi value initialized by the
constructor.
Or you could construct a Quasi like this: new Quasi('foo ${bar}'); or
Quasi('foo ${bar}')
This way Quasi's would be straight forward to use and can be implemented
without any additional grammar magic.
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/9be9d9d8/attachment.html>
More information about the es-discuss
mailing list