arguments是對象,不是數組,能夠理解爲類數組,有length屬性。html
動態參數。數組
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<script>
function add(){
let len = arguments.length;
this.result=0;
for(var i=0;i<len;i++){
this.result=this.result+arguments[i];
}
console.log(this.result);
}
//測試用例
add(1,2);
add(1,2,3);
</script>
</body>
</html>
複製代碼
MDNbash