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

Tagged Template Literals & ES6 Template Literals/ ES6 Template Strings #5

Open
xgqfrms opened this issue Apr 25, 2018 · 1 comment
Open

Comments

@xgqfrms
Copy link
Owner

xgqfrms commented Apr 25, 2018

Tagged Template Literals & ES6 Template Literals/ ES6 Template Strings

ES6 Template Strings & Tags

"use strict";

/**
 *
 * @author xgqfrms
 * @license MIT
 * @copyright
 * @description Tagged Template Literals &  ES6 Template Literals/ ES6 Template Strings
 * @augments
 * @example
 * @param {*} strings
 * @param {*} name
 * @param {*} age
 *
 */


const highlight = (strings, name, age) => {
    return `
        <div>
            <p>
                ${strings[0]}: <span style="color: #0f0; background: #000;">${name}</span>,
                ${strings[1]}: <span style="color: #0f0; background: #000;">${age}</span>,
                ${strings[2]}.
            </p>
        </div>
    `;
};


let name = "xgqfrms",
    age = 23,
    sentence = highlight`My name is ${name} and ${age} years old.`;
console.log(sentence);

const body = document.querySelector("body");
body.innerHTML = "";
body.insertAdjacentHTML("beforeend", sentence);

image

Repository owner locked and limited conversation to collaborators Apr 25, 2018
@xgqfrms
Copy link
Owner Author

xgqfrms commented Apr 25, 2018

"use strict";

/**
 *
 * @author xgqfrms
 * @license MIT
 * @copyright  xgqfrms
 * @description Tagged Template Literals &  ES6 Template Literals/ ES6 Template Strings
 * @augments ES6 Template Strings & Tags
 * @example ...
 * @param {*} strings
 * @param {*} name
 * @param {*} age
 * @reference https://wesbos.com/tagged-template-literals/
 *
 */


const highlight = (strings, name, age) => {
    return `
        <div>
            <p>
                ${strings[0]}: <span style="color: #0f0; background: #000;">${name}</span>,
                ${strings[1]}: <span style="color: #0f0; background: #000;">${age}</span>,
                ${strings[2]}.
            </p>
        </div>
    `;
};

let name = "xgqfrms",
    age = 23,
    sentence = highlight`My name is ${name} and ${age} years old.`;
console.log(sentence);

const body = document.querySelector("body");
body.innerHTML = "";
body.insertAdjacentHTML("beforeend", sentence);

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

No branches or pull requests

1 participant