callee속성

최신 자바스크립트 엔진에서 argument.callee를 사용하면 성능이 확 떨어진다.(비추천)

 

callee 속성은 관련된 함수가 실행될 때만 사용 가능한 arguments 개체의 멤버입니다.

arguments.callee 속성(property)은 현재 실행 중인 함수를 포함합니다.

callee 속성의 초기 값은 실행 중인 Function 개체입니다. 

이 속성은 익명 함수의 재귀를 허용합니다.

 

function factorial(n){
  if (n <= 0)
     return 1;
  else
     return n * arguments.callee(n - 1)
}
console.log(factorial(4));

// 결과 24

 

caller속성

 

현재 함수를 호출한 함수를 가져옵니다.

 

caller 속성은 함수가 실행 중인 경우에만 해당 함수에 대해 정의됩니다. 

JavaScript 프로그램의 맨 위 수준에서 함수를 호출하면 caller는 null을 포함합니다.

 

caller 속성을 문자열 컨텍스트에 사용하면 functionName.toString과 같은 결과가 나옵니다.

즉, 함수의 역컴파일된 텍스트가 표시됩니다.

function CallLevel(){
   if (CallLevel.caller == null)
      return("CallLevel was called from the top level.");
   else
      return("CallLevel was called by another function.");
}

consloe.log(CallLevel());

// Output: CallLevel was called from the top level

 

 

참고사이트 : https://blog.naver.com/PostView.naver?blogId=mrshin2000&logNo=130177264976&parentCategoryNo=&categoryNo=14&viewDate=&isShowPopularPosts=true&from=search

+ Recent posts