最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

TypeScript之調用棧的實現(xiàn)

 更新時間:2019年12月31日 09:17:26   作者:Aonaufly  
這篇文章主要介紹了TypeScript之調用棧的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧

本文介紹了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)}: \n ${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的參數(shù)取一些好的名字.

另外一點 , 不會出現(xiàn)function()這樣的打印 , 出現(xiàn)沒有參數(shù)的function , 我會將方法體內容也打印出來

如果需要把每一個function的方法體的內容打印出來CallStackTool.printCallStack(2,false), 將第二個參數(shù)設置未false

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

最新評論

虹口区| 肇东市| 嘉鱼县| 南溪县| 宜章县| 沿河| 南雄市| 延吉市| 乌海市| 迁西县| 漯河市| 施秉县| 辉县市| 舞阳县| 开化县| 裕民县| 永和县| 紫阳县| 鞍山市| 工布江达县| 荥经县| 淳安县| 鄂州市| 菏泽市| 瑞丽市| 左云县| 平阴县| 张家港市| 塔河县| 田阳县| 门源| 台东市| 台中县| 崇文区| 腾冲县| 巩义市| 神池县| 曲松县| 寿阳县| 克东县| 灵石县|