util.ts

class UtilService{

   util( tis,callback:any ){

    let num = 1;

    callback(tis,num); 

  }

}

 

使用该方法的文件

demo.ts

class Demo{

  //设置一个全局变量

  count = 4;

  console.log("count1:"+count1);  //结果为4

   this.UtilService.util( this , function(tis,num){

    tis.count = num; //用num改变全局变量count的值

    console.log("count2:"+tis.count );    //结果为1

  }

   

  console.log("count3:"+this.count);  //结果为1

}

 

相关文章:

  • 2021-07-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-27
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-18
  • 2022-12-23
  • 2021-06-20
  • 2021-10-06
  • 2021-11-18
相关资源
相似解决方案