ES6 & tagged-template-literals & template strings

tagged template

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#Tagged_templates

demo

https://wesbos.com/tagged-template-literals/


function highlight(strings, ...values) {
let str = '';
strings.forEach((string, i) => {
str += string + (values[i] || ``);
});
return str;
} const name = 'Snickers';
const age = '100';
const sentence = highlight`My dog's name is ${name} and he is ${age} years old`; console.log(sentence);
// My dog's name is Snickers and he is 100 years old


tagged-template-literals

https://www.leighhalliday.com/tagged-template-literals

https://www.freecodecamp.org/news/es6-tagged-template-literals-48a70ef3ed4d/

https://www.freecodecamp.org/news/a-quick-introduction-to-tagged-template-literals-2a07fd54bc1d/

https://dev.to/sarah_chima/tagged-template-literals-2ho

https://exploringjs.com/impatient-js/ch_template-literals.html#tagged-templates

demo

https://github.com/mqyqingfeng/Blog/issues/84


let x = 'Hi', y = 'Kevin';
const res = message`${x}, I am ${y}`;
console.log(res); // 我们可以自定义 message 函数来处理返回的字符串: // literals 文字
// 注意在这个例子中 literals 的第一个元素和最后一个元素都是空字符串
function message(literals, value1, value2) {
console.log(literals); // [ "", ", I am ", "" ]
console.log(value1); // Hi
console.log(value2); // Kevin
}

React & styled-components

https://www.styled-components.com/

https://github.com/styled-components/styled-components


const Button = styled.a`
/* This renders the buttons above... Edit me! */
display: inline-block;
border-radius: 3px;
padding: 0.5rem 0;
margin: 0.5rem 1rem;
width: 11rem;
background: transparent;
color: white;
border: 2px solid white; /* The GitHub button is a primary button
* edit this to target it specifically! */
${props => props.primary && css`
background: white;
color: palevioletred;
`}
`;

demo


"use strict"; /**
*
* @author xgqfrms
* @license MIT
* @copyright xgqfrms
* @created 2019-08-16
*
* @description tagged-template-literals
* @augments
* @example
* @link https://github.com/lydiahallie/javascript-questions#17-whats-the-output
*
*/ let log = console.log; function getPersonInfo(one, two, three) {
log(one);
log(two);
log(three);
} const person = "xgqfrms";
const age = 23; getPersonInfo`${person} is ${age} years old`;
// [ '', ' is ', ' years old' ]
// xgqfrms
// 23


xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!


ES6 & tagged-template-literals & template strings的更多相关文章

  1. Template literals

    [Template literals] Template literals are string literals allowing embedded expressions. You can use ...

  2. Django.template框架 template context (非常详细)

    前面的章节我们看到如何在视图中返回HTML,但是HTML是硬编码在Python代码中的 这会导致几个问题: 1,显然,任何页面的改动会牵扯到Python代码的改动 网站的设计改动会比Python代码改 ...

  3. Package template (html/template) ... Types HTML, JS, URL, and others from content.go can carry safe content that is exempted from escaping. ... (*Template) Funcs ..

    https://godoc.org/text/template GoDoc Home About Go: text/templateIndex | Examples | Files | Directo ...

  4. Error resolving template [xxx], template might not exist or might not be exist

    Springboot+thymeleaf+mybatis 抛Error resolving template [xxx], template might not exist的异常 原因是我们在pom. ...

  5. Error resolving template: template might not exist or might not be accessible是一句缩水报错?

    一 thymeleaf在开发的时候本地调试正常,但是在测试环境打成jar包就报这个错误了. 二 template might not exist or might not be accessible ...

  6. 【报错】An error happened during template parsing (template: "class path resource [templates/adminManageCourse.html]")

    页面显示: Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing t ...

  7. 【报错】An error happened during template parsing (template: "class path resource [templates/hello1.html]")

    页面显示: Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing t ...

  8. Thymeleaf 异常:Exception processing template "index": An error happened during template parsing (template: "class path resource [templates/index.html]")

    Spring Boot 项目,在 Spring Tool Suite 4, Version: 4.4.0.RELEASE 运行没有问题,将项目中的静态资源和页面复制到 IDEA 的项目中,除了 IDE ...

  9. ES6 Features系列:Template Strings & Tagged Template Strings

    1. Brief ES6(ECMAScript 6th edition)于2015年7月份发布,虽然各大浏览器仍未全面支持ES6,但我们可以在后端通过Node.js 0.12和io.js,而前端则通过 ...

  10. 异常:Error resolving template "xxx", template might not exist or might not be accessible...解决办法

    在开发环境下正常,但使用jar运行时,报错Error resolving template template might not exist or might not be accessible,意思 ...

随机推荐

  1. Index-Only Scans and Covering Indexes

    小结: 1.覆盖索引 回表 2. All indexes in PostgreSQL are secondary indexes, meaning that each index is stored ...

  2. 强制杀死进程后,进程相关的socket未必发送RST

    强制杀死进程后,进程相关的socket未必发送RST

  3. .Vue-router跳转和location.href有什么区别

    使用location.href='/url'来跳转,简单方便,但是刷新了页面:使用history.pushState('/url'),无刷新页面,静态跳转:引进router,然后使用router.pu ...

  4. centos7+python3+selenium+chrome

    一.安装GUI图形化界面 (1)安装GUI图形化界面 yum groupinstall "GNOME Desktop" "Graphical Administration ...

  5. 【算法】深度优先搜索(dfs)

    突然发现机房里有很多人不会暴搜(dfs),所以写一篇他们能听得懂的博客(大概?) PS:万能 yuechi ---- 大法师怎么能不会呢?! 若有错误,请 dalao 指出. 前置 我知道即使很多人都 ...

  6. office提示“应用程序无法正常启动(0xc0000142)。请单击确认关闭应用程序”

    打开word文档,突然弹出如下提示框: 网上查询,说应用程序无法正常启动(0xc0000142)的原因可能是缺少组件导致的.控制面板 - 时钟和区域 - 更改日期.时间或数字格式 - 管理 - 更改系 ...

  7. GeoServer发布Shapfile、PostGIS数据

    GeoServer发布Shapfile.PostGIS数据 一.GeoServer发布Shapfile数据 1.1 创建工作区 1.1.1 工作区 1.2 在工作区中加入新的数据存储 1.2.1 数据 ...

  8. 希尔伯特曲线python3实现

    需要OpenGL库:https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyopengl #coding:utf-8 from OpenGL.GL import * ...

  9. 面向对象编程(封装、封装的意义、封装与扩展性、@property)

    1.封装之如何实现属性的隐藏 封装: __x=1 # 把数据属性隐藏 (如何实现隐藏) 类定义阶段 __开头发生了变形 __x --> _A__x特点: 1.在类外部无法直接:obj.__Att ...

  10. java格式化json串

    package com.loan.modules.extbiz.in.rabbitmq.util; import com.loan.modules.extbiz.in.rabbitmq.excepti ...