컴퓨터/JavaScript_typescript

[JavaScript] arguments

수제녹차 2020. 10. 4. 14:40
728x90
반응형

* arguments

 

* the arguments object does not exist inside arrow functions, only traditional ones.

화살표 함수에서는 arguments를 사용할 수 없다.

 

* The arguments object returns an array-like list of the arguments that are passed into a function.

=> arguments는 array의 prototype을 상속하지 않는다

var maxOfThree = function () {

	// If there's more than three arguments
	if (arguments.length > 3) {
		throw new Error('A max of three parameters are allowed.');
	}

	// Run the Math.max() method, with the arguments passed in
	return Math.max.apply(null, arguments);

};

함수 body block 안에서 매개변수에 접근할 수 있다.

Note : rest 연산자로 정의한 parameter는 배열이다. array의 prototype을 상속한다.

반응형