Raymond Sohn
What Are Template Strings?
Before
What Are Tagged Template Strings?
GraphQL Tag
How Do Tagged Template Strings Work?
Arguments Tag
NO-OP Tag
function noop(strings, ...values) {
var result = '';
// Append each string to the result.
strings.forEach((string, index) => {
result += string;
// If a value exists then append it to the result.
if (index < values.length) {
result += values[index];
}
});
return result;
}
var value = 'No Operation';
noop`Hello ${value}!`
What Else Can We Do
With Tagged Template Strings?
Embed Domain Specific Languages
Metaprogramming
Async Programming
Quantum Computing
Single File Web Components with LitElement
Shell Tag
Abstract Syntax Tree Tag
Promise Tag
function p(strings, ...promises) {
// Return a promise for the caller to wait on.
return new Promise((resolve, reject) => {
// Wait for all of the promises to resolve.
Promise.all(promises).then(values => {
var result = '';
strings.forEach((string, index) => {
… // Concatenate the template string.
});
// Resolve the promise with the result.
resolve(result);
}, reject);
});
}
Simulating Quantum Circuits with Q.js
Thank you for your time. You can find more examples, the slides and the transcript for this talk at git.io/JvSGK.