TypeScript自定义函数

来源:互联网 发布:淘宝浏览器崩溃 编辑:程序博客网 时间:2024/05/09 16:42
 1、函数参数不可选:

            private  fun(a){
                    return a;
            }

            调用是 console.log( fun( 2 ) );


 2、函数参数可选,没有传递的参数取默认值:
private argument( a, b=1, c=1 ){
return a*b*c;
}
//调用
var a = 3;
console.log( "参数一个 " + this.argument( a ) );
console.log( "参数二个 " + this.argument( a, 2 ) );
console.log( "参数三个 " + this.argument( a, 2, 3 ) );
//输出结果
参数一个  3 
参数二个  6 
参数三个  18 

3、在TypeScript方法里面使用function
//在函数里面不能识别this因此要用self来代替this的作用
var self = this;
function setInfo(){
console.log( );
}
//调用
setInfo();

0 0
原创粉丝点击