Template Strings - Confusing Example
gsklee opened this issue · 3 comments
gsklee commented
GET`http://foo.org/bar?a=${a}&b=${b}
Content-Type: application/json
X-Credentials: ${credentials}
{ "foo": ${foo},
"bar": ${bar}}`(myOnReadyStateChangeHandler);
I don't understand this example; can we have more explanation on this? Otherwise it looks bugged for me.
basarat commented
good explanation
lukehoban commented
The original example in the post actually has one additional interesting element that isn't captured in @chuyik's implementation example.
Tagged templates can return any kind of object, not just a string. In this example, the GET
tag returns a function which makes a request to the provided URI with a callback myOnReadyStateChangeHandler
passed to the function.