TypeScript 호출 스 택 구현
2290 단어 TypeScript호출 창고
class CallStackTool{
private static index:number = 0;
public static printCallStack (count:number , simple: boolean = true):void {
let caller:Function = arguments.callee.caller;
let i:number = 0;
count = count || 10;
CallStackTool.index ++;
if( CallStackTool.index > 500 ) CallStackTool.index = 1;
console.log(`***-----------------${CallStackTool.index}Start----------------------- **`);
while (caller && i < count) {
console.log(`${(i+1)}:
${CallStackTool.getFunctionName(caller,simple)}`);
caller = caller.caller;
i++;
}
console.log(`***-----------------${CallStackTool.index}End----------------------- **`);
}
private static getFunctionName(func:any,simple: boolean):string {
if( simple ){
let name:any;
if ( typeof func == 'function' ) {
name = ('' + func).match(/function\s*\((\s*\$*\S+\s*,)*(\s*\$*\S+\s*)?\)/g);
let $result: string = name && name[0];
if( $result != `function ()` ){
return $result;
}
}
}
return func.toString();
}
}
테스트 코드:
class Test2CallStack{
public add( i:number, b:number ):number{
CallStackTool.printCallStack(2,true);
return i +b;
}
public a( c:number, q:number ): number{
return this.add(c,q);
}
public print() : void{
console.log(`${this.a(1,1)}`);
}
}
테스트 시작:결과:
그래서 가능 한 한 function 의 매개 변수 에 좋 은 이름 을 지어 주세요.
또 하 나 는 function()와 같은 인쇄 가 나타 나 지 않 고 인자 가 없 는 function 이 나타 나 지 않 습 니 다.방법 체 내용 도 인쇄 하 겠 습 니 다.
모든 function 의 방법 체 의 내용 을 출력 해 야 한다 면 CallStackTool.printCallStack(2,false),두 번 째 매개 변 수 를 false 가 아 닌 것 으로 설정 합 니 다.
이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Cypress에서 Stripe Elements의 자동 테스트 수행을 사용하여 E2E 테스트를 작성할 때 약간의 고려가 필요했기 때문에 비망으로 남겨 둡니다 ✍️ 을 사용하여 이런 코드에서 카드 번호 입력 요소를 만들었습니다. 본래라면, 카드 정보의 입력이 다른 도메인(Stripe...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.