函数和对象
函数类似swift
<script>
fuction look(){
}
//调用
look();
</script>
//加法运算
<script>
fuction sum(num1,num2){
reture num1 + num2;
}
//调用
var result = sum(10,20);
console.log(result);
</script>
<script>
function sum([numers]) {
var add = 0;
for (var i =0;i<numers.length;i++){
add += numers[i];
}
return add;
}
var result2 = sum([55,0,1,1,3,2]);
console.log(result2);
</script>
//函数中有个内置数组
<script>
function sum3() {
var add = 0;
for (var i =0;i<arguments.length;i++){
add += arguments[i];
}
return add;
}
console.log(sum3(12,12,3,1,4));
</script>
//匿名函数
var score = function(){
}
score();
[] ,{} 这里都是js中的对象,主要是用于数据的传递
网友评论