검색결과 리스트
arguments에 해당되는 글 1건
글
arguments.callee
This property is a reference to the function that you are in. Which is very handy if you want to get a reference to an anonymous function from inside itself. One good reason for doing this would be in a recursive anonymous function.arguments.caller
This property is a reference to the function that called the function you are in. This allows you to get access to the entire current callstack which is very handy for debugging.
function test() {
console.log(">>>test");
console.log("arguments.callee\n" + arguments.callee);
console.log("arguments.caller\n" + arguments.caller);
console.log("arguments.callee.caller\n" + arguments.callee.caller);
test1();
}
function test1() {
console.log(">>>test1");
console.log("arguments.callee\n" + arguments.callee);
console.log("arguments.caller\n" + arguments.caller);
console.log("arguments.callee.caller\n" + arguments.callee.caller);
}
test();
// 로그기록
//>>>test
//arguments.callee
//function test() {
// console.log(">>>test");
// console.log("arguments.callee\n" + arguments.callee);
// console.log("arguments.caller\n" + arguments.caller);
// console.log("arguments.callee.caller\n" + arguments.callee.caller);
// test1();
//}
//arguments.caller undefined
//arguments.callee.caller null
//>>>test1
//arguments.callee
//function test1() {
// console.log(">>>test1");
// console.log("arguments.callee\n" + arguments.callee);
// console.log("arguments.caller\n" + arguments.caller);
// console.log("arguments.callee.caller\n" + arguments.callee.caller);
//}
//arguments.caller undefined
//arguments.callee.caller
//function test() {
// console.log(">>>test");
// console.log("arguments.callee\n" + arguments.callee);
// console.log("arguments.caller\n" + arguments.caller);
// console.log("arguments.callee.caller\n" + arguments.callee.caller);
// test1();
//}
위와 같이 오출하면 로그(firefox)이 찍힌다.
결국 arguments.callee 는 함수의 입장에서 자기자신
arguments.callee.caller 는 arguments.callee를 호출한 함수이다.
호출한 쪽이 함수가 아니라 전역환경이라면
arguments.callee.caller null 이다.
arguments.callee는 익명함수의 재귀호출에 유용하다.
* 추가적으로 callee, caller가 null이거나 undefined가 아닐때
Object.prototype.toString.call(arguments.callee);
Object.prototype.toString.call(arguments.callee.caller);
호출해 보면은 둘다 [object Function]을 리턴하는것을 알수 있다.
'JavaScript > JavaScript' 카테고리의 다른 글
[javascript] .search(), .replace(), .match() 및 정규표현식 플래그 (0) | 2012.02.09 |
---|---|
[javascript] hasOwnProperty, in 객체의 프로퍼티 존재 여부 확인 (0) | 2012.02.08 |
[javascript] JSON.stringify() 메소드 만들어 보기 (0) | 2012.02.08 |
[javascript] DOMContentLoaded (0) | 2012.01.18 |
[Javascript] Enter 키 클릭시 전송기능 구현 (0) | 2011.12.19 |
RECENT COMMENT