#声明的函数被调用时 参数的个数要和声明是参数的个数一样!!!!函数的定义!!!!#es5函数声明function f(){ console.log("hello f");}f();#es5 匿名函数var f2=function () { console.log("hello f2");}f2();//调用函数#ts中没有返回值的函数function run():void{ console.log('run')}run();//调用函数#ts中指定返回值类型(number)的函数var run2=function():number{ return 123;}console.log(run2());//调用函数
1、函数传参
function fun(s:string="hello world"):string{ console.log(s); return s;}fun();
2、自定义参数
function fun(s:string):string{ console.log(s); return s;}fun("good");
3、任意类型
function func(s:any):any{ return s;}