함수 객체의 length
프로퍼티는 함수를 작성할 때 정의한 인자 개수를 나타낸다.
function func2(x,y){
return x + y;
}
function func3(x,y,z){
return x + y + z;
}
console.log('func2.length - ' + func2.length); // func2.length - 2
console.log('func3.length - ' + func3.length); // func3.length - 3
모든 함수는 객체로서 prototype
프로퍼티를 가지고 있다. prototype
프로퍼티는 모든 객체의 부모를 나타내는 내부 프로퍼티인 [[Prototype]]과는 다르다. 함수 객체가 가지는 prototype
프로퍼티는 이 함수가 생성자로 사용될 때 이 함수를 통해 생서오딘 객체의 부모 역활을 하는 프토토타입 객체를 가리킨다.
prototype
프로퍼티는 함수가 생성될 때 만들어지며, constructor
프로퍼티 하나만 있는 객체를 가리킨다. 그리고 프로토타입 객체의 유일한 constructor
프로퍼티는 자신과 연결된 함수를 가리킨다.
즉, 자바스크립트에서는 함수를 생성할 때, 함수 자신과 연결된 프로토타입 객체를 동시에 생성되며, 각각 prototype
과 constructor
라는 프로퍼티로 서로를 참조하게 된다.
function myFunction(){
return true;
}
console.dir(myFunction.prototype);
console.dir(myFunction.prototype.constructor);