提问者:小点点

调用不带括号的JS函数[重复]


今天我第一次看到JS语法。 在Microsoft MSSQL client for nodeJS中有以下示例:

const sql = require('mssql')
 
async () => {
    try {
        // make sure that any items are correctly URL encoded in the connection string
        await sql.connect('mssql://username:password@localhost/database')
        const result = await sql.query`select * from mytable where id = ${value}`
        console.dir(result)
    } catch (err) {
        // ... error checks
    }
}

这一行是什么意思:

await sql.query`select * from mytable where id = ${value}`

看起来querySQL对象上的一个方法,但是它怎么可以这样调用呢? 是否将此附加的内插字符串作为参数传递? 这个JS特性叫什么名字?


共1个答案

匿名用户

这个功能称为“标记模板”

https://developer.mozilla.org/en-us/docs/web/javascript/reference/template_literals