简体   繁体   中英

ES6 Template strings: how to nest them?

I'd like to nest them like this but I get error. Is there a way?

let greetings1 = 'hello1';
let greetings2 = 'hello2';

let template1 = ``${greetings1}``;
let template2 = ``${greetings2}``;

let template = `${template1}`;
console.log(template);

I hope this helps.

 let greetings1 = 'hello1'; let greetings2 = 'hello2'; let template = `${greetings1} ${greetings2}`; console.log(template);

The problem is the double quotation marks

 let greetings1 = 'hello1'; let greetings2 = 'hello2'; let template1 = `${greetings1}`; let template2 = `${greetings2}`; let template = `${template1}`; console.log(template);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM