es6templatestring

0.0.0 • Public • Published

es6TemplateString

使用ejs和multiline 实现ES6 Template String的功能

ES6 Template String 支持的功能

//Basic usage with an expression placeholder
var person = 'Hao Ju Zheng';
console.log(`Yo! My name is ${person}`);
 
//Expressions work just as well with object literals
var user = {name: 'Zhen Ou Yun'};
console.log(`Thanks, ${user.name}`);
 
//Expression interpolation, One use is readable inline math.
var a = 50;
var b = 100;
console.log(`The number of JS frameworks is ${+ b} and not ${ 2 * a +}`);
 
//Multi-line strings without needing \n\
console.log(`string text line 1
string text line 2`);
 
//Function inside expressions
function fn() {return "result"}
console.log(`foo ${fn()} bar`);

浏览器支持情况

详见ES6兼容表

使用ejs和multiline的实现的es6TemplateString

//Basic usage with an expression placeholder
var person = "Hao Ju Zheng";
 
console.log(es6TemplateString(function(){/*!
Yo My name is ${= person }
*/}, {'person': person}));
 
 
//Expressions work just as well with object literals
var user = {name: "Zhen Ou Yun"};
 
console.log(es6TemplateString(function(){/*!
Thanks, ${= name }
*/}, user));
 
 
//Multi-line strings without needing \n\
console.log(es6TemplateString(function(){/*!
string text line 1
string text line 2
*/}, {}));
 
 
//Function inside expressions
function fn() {return "result"}
console.log(es6TemplateString(function(){/*!
foo ${= fn() } bar
*/}, {'fn': fn}));

使用es6TemplateString

关于更多问题,大家可以参见ejsmultiline的README文件

Readme

Keywords

none

Package Sidebar

Install

npm i es6templatestring

Weekly Downloads

1

Version

0.0.0

License

MIT

Last publish

Collaborators

  • hjzheng