JavaScript模板字符串传参数
JavaScript模板字符串传参数
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>模板字符串传参数</title>
</head>
<body>
<script>
let name = "cls";
let age = 18;
/**
*
* @param params [Array] 用于接收模板字符串 ${} 之前的字符串
* @param name
* @param age
*/
function test(params, name, age) {
// ['111', '222', '333'] 'cls' 18
console.log(params, name, age);
}
test`111${name}222${age}333`;
</script>
</body>
</html>