Đối tượng đối số trong JavaScript là một đối tượng, đại diện cho các đối số để thực thi hàm. Cú pháp của nó có hai đối số:
[function.]arguments[p]
Ví dụ
Bạn có thể thử chạy đoạn mã sau để tìm hiểu đối tượng đối số trong JavaScript là gì
Bản trình diễn trực tiếp
<html>
<body>
<script>
function functionArgument(val1, val2, val3) {
var res = "";
res += "Expected Arguments: " + functionArgument.length;
res += "<br />";
res += "Current Arguments : " + arguments.length;
res += "<br />";
res += "Each argument = "
for (p = 0; p < arguments.length; p++) {
res += "<br />";
res += functionArgument.arguments[p];
res += " ";
}
document.write(res);
}
functionArgument(20, 50, 80, "Demo Text!","Hello World", new Date())
</script>
</body>
</html>