ES6 template literals are one of my favorite features in es6. A few days ago I saw an open source project on github - htm, there are also hyperHTML and, possibly, several other projects also.And I decided to create such a thing to perform AJAX requests.
By the way, package uses node-fetch for node.js and whatwg-fetch for client javascript
Source in github vaheqelyan/karin
Top comments (16)
Nice.
A few years ago I read somebody talking about the fact that templates can be used as an alternative function syntax. I found this quite funny. Why would anyone do this to save two characters?
It turns out, many things in JavaScript are already done with strings and the fact that these are string templates and not just plain strings makes them rather powerful and with Babel plugins they can be converted to regular function calls before hitting production.
I started a awesome list for this kind of stuff, maybe this will become more of a thing in the future :D
awesome-tagged-templates
Jest is using this in
each
See point 2:
jestjs.io/docs/en/api#testeachtabl...
Huge fan of the idea! I'd love to see it accept something like the usual HTTP request format, with headers on the line below the URL, then a blank line, then a request body if there is one. I'd also love to see support for converting an object into query parameters, maybe even an object for additional headers, etc.
This request:
could be made like this:
But what about this
Perhaps we can include both examples?
All depends on how complex you want your parser to be, I guess. Personally I'm not sold on a shell-command-like format, especially considering that it would be kind of annoying to build that string in JS I think. Would you specify just certain header options that can be specified with this shorthand?
I personally like the
Header-Name: header-value
syntax because it's very easy to parse into an Object, and its very easy to serialize an Object into that format. But it's all subjective; it's just a prototype, right? Have fun with it, try it out, use it for a project, see what you like and dislikeI agree with you
Wow.it will look really good.maybe I should rethink and rewrite?
Omg. I never heard this before. But I think this isn't a good feature. This look like a Ruby' method calling.
In the Ruby Programming Language you can like this;
I realized now, you can use this feature also in the JavaScript.
I think that feature decreasing the readability in the JavaScript. Maybe some people disagree with me.
Even so ?
Using:
I don't want to misunderstand. This post so informative. Thanks for this. I just don't like this syntax :D
But this syntax acceptable. Which means, we'll use some libraries that use this syntax.
In my opinion, this syntax is more valid
Thanks to Ken Bellows for the idea
I personally like it! A couple years back when I proposed this on reddit/r/javascript (I think I was using it with a logging library), I got a lot of backlash - people are resistant to change.
I think this is really interesting use of the syntax. I need to do some experiments with tagged template literals so that I can come up with cool stuff like this!
I don't think it was a good idea, looks like normal function calls, but with extra steps.
I fail to perceive any value in this, is it even solving any problem?