함수는 객체이다. 따라서 함수도 프로퍼티를 가질 수 있다.
함수는 일반 객체와는 다른 함수만의 프로퍼티를 갖는다.
function square(number) {
return number * number;
}
console.dir(square);
arguments 객체는 함수 호출 시 전달된 인수(argument)들의 정보를 담고 있는 순회가능한(iterable) 유사 배열 객체(array-like object)이며 함수 내부에서 지역변수처럼 사용된다. 즉, 함수 외부에서는 사용할 수 없다.
function multiply(x, y) {
console.log(arguments);
return x * y;
}
multiply(); // {}
multiply(1); // { '0': 1 }
multiply(1, 2); // { '0': 1, '1': 2 }
multiply(1, 2, 3); // { '0': 1, '1': 2, '2': 3 }
매개변수(parameter)는 인수(argument)로 초기화된다.
undefined으로 초기화된다.유사배열객체란 length 프로퍼티를 가진 객체를 말한다. 유사배열객체는 배열이 아니므로 배열 메소드를 사용하는 경우 에러가 발생하게 된다. 따라서 배열 메소드를 사용하려면 Function.prototype.call, Function.prototype.apply를 사용하여야 하는 번거로움이 있다.
Function.prototype.call, Function.prototype.apply ****공부하기
caller 프로퍼티는 자신을 호출한 함수를 의미한다.