简体   繁体   English

这个信号在 TypeScript 中是什么意思?

[英]What does this signal mean ' in TypeScript?

In this code snippet在此代码段中

return new this(`${last}, ${first} ${middle}`.trim(),
            utils.age(birthday),
            gender
        );

what does this signal mean '?这个信号是什么意思?

If you mean the backtick symbol (`), it denotes a template literal or template string .如果您指的是反引号 (`),它表示template literaltemplate string

From the Typescript documentation :来自Typescript 文档

Template literals can contain placeholders.模板文字可以包含占位符。 These are indicated by the dollar sign and curly braces (${expression}).这些由美元符号和花括号 (${expression}) 表示。 The expressions in the placeholders and the text between the backticks (` `) get passed to a function.占位符中的表达式和反引号 (` `) 之间的文本被传递给 function。

The default function just concatenates the parts into a single string.默认的 function 只是将部分连接成一个字符串。 If there is an expression preceding the template literal (tag here), this is called a tagged template.如果模板字面量(此处为标记)之前有表达式,则称为标记模板。 In that case, the tag expression (usually a function) gets called with the template literal, which you can then manipulate before outputting.在这种情况下,标签表达式(通常是一个函数)会被模板文字调用,然后您可以在输出之前对其进行操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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