美文网首页我爱编程
TypeScript——函数-重载

TypeScript——函数-重载

作者: _____西班木有蛀牙 | 来源:发表于2018-05-23 00:20 被阅读16次
function attr(name:string):string;
function attr(age:number):numbner;

function attr(nameorage:any):any{
    if (nameorage && typeof nameorage === 'string') {
        alert('姓名');
    } else {
        alert('年龄');
    }
}

attr("哈哈"); // 姓名
attr(123444); // 年龄

相关文章

网友评论

    本文标题:TypeScript——函数-重载

    本文链接:https://www.haomeiwen.com/subject/nsdljftx.html