我爱编程

TypeScript 函数-可变参数

2018-03-19  本文已影响155人  神秘者007

参考网址:https://www.tslang.cn/docs/handbook/functions.html 剩余参数

image.png
//...restOfname:string[]  这个写法就是可变参数的写法
function peopleName(firstName:string,...restOfname:string[]){
    return firstName + " " + restOfname.join(" ");
}
let pn1 = peopleName('xiaochuan','xiaoming','xiaohong');//编译成功
let pn2 = peopleName('xiaochuan','xiaoming','xiaohong','xiaoxin');//编译成功

document.getElementById('pid').innerHTML = pn1 + "<br/>" + pn2;

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>TypeScript 函数-可变参数</title>
</head>
<body>
    <p id="pid"></p>
    <script type="text/javascript" src="Functions.js"></script>
</body>
</html>

上一篇下一篇

猜你喜欢

热点阅读