Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An interesting addition to the template strings section #94

Open
softwarespot opened this issue Sep 13, 2015 · 1 comment
Open

An interesting addition to the template strings section #94

softwarespot opened this issue Sep 13, 2015 · 1 comment

Comments

@softwarespot
Copy link

function valueToUpper(strings, ...values) {
    // Set the values i.e. first and last name to upper-case
    values[0] = values[0].toUpperCase();
    values[1] = values[1].toUpperCase();

    // Re-create the template
    return `${strings[0]}${values[0]}${strings[1]}${values[1]}${strings[2]}`;
}

// Create first and last name variables
let firstName = 'Joe';
let lastName = 'Bloggs';

// Pass the template to a custom format function
let template = valueToUpper`Welcome ${firstName} ${lastName} to the site.`;

// Diplsay the new template
console.log(template);
@knpwrs
Copy link

knpwrs commented Sep 13, 2015

Probably worth pointing out that these are called Tagged Template Strings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants