js中声明函数的方法

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript">
/**
* 函数声明的三种方式
*
* 第一种 函数式声明
* 第二种 表达式声明
* 第三种 构造器声明
*
*/

function test(){}

var a = test;
var b = test();

/**
* 表达式声明
*
* 是在执行的时候才会解析相应的代码
*
*/
var c = function (){}

var add = function (){
var args = arguments;
if(args.length===1){
return args[0]+101;
}else if(args.length === 2){
return args[0]*args[1];
}else{
return "还没有被实现";
}
}
var n1 = add(200);

var n2 = add(200,200);
var n3 = add(200,200,100);
var n4 = add(200,200,200,500);
console.log(n1);
console.log(n2);
console.log(n3);
console.log(n4);

var aa = new Function("a","b","c","alert(a+b+c)")
</script>
</head>
<body>

</body>
</html>
原文地址:https://www.cnblogs.com/hwgok/p/5715486.html