18장 함수와 일급 객체 ⭐⭐
18.1 일급 객체
// 1. 함수는 무명의 리터럴로 생성할 수 있다.
// 2. 함수는 변수에 저장할 수 있다.
// 런타임에 함수 리터럴이 평가되어 함수 객체가 생성되고 변수에 할당된다.,
const increase = function(num){
return ++num
}
const decrease = function(num){
return --num
}
// 2. 함수는 객체에 저장할 수 있다.
const auxs = { increase, decrease }
// 3. 함수는 매개변수에 전달할 수 있다.
// 4. 함수의 변환값으로 사용할 수 있다.
function makeCounter(aux){
let num = 0
return function(){
num = aux(num)
return num
}
}
// 3. 함수는 매개변수에 전달할 수 있다.
const increaser = makeCounter(auxs.increase)
console.log(increaser()) // 1
console.log(increaser()) // 2
const decreaser = makeCounter(auxs.decrease)
console.log(decreaser()) // -1
console.log(decreaser()) // -218.2 함수 객체의 프로퍼티
18.2.1 arguments 프로퍼티

18.2.2 caller 프로퍼티
18.2.3 length 프로퍼티
18.2.3 name 프로퍼티
18.2.5 proto 접근자 프로퍼티
18.2.6 prototype 프로퍼티
Last updated