最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Typescript: Calling method from another method of current class - Stack Overflow

programmeradmin1浏览0评论

Supposably, I have this class:

Class ExampleClass {  
    public firstMethod(){
     // Do something  
    }  
    public secondMethod(){
     //Do something with invoke firstMethod
    }
}

How can I invoke first method from another correctly? (Simple "firstMethod()" is not working).

Supposably, I have this class:

Class ExampleClass {  
    public firstMethod(){
     // Do something  
    }  
    public secondMethod(){
     //Do something with invoke firstMethod
    }
}

How can I invoke first method from another correctly? (Simple "firstMethod()" is not working).

Share Improve this question edited Nov 17, 2016 at 12:32 Vlad Dekhanov asked Jan 20, 2014 at 17:48 Vlad DekhanovVlad Dekhanov 1,0841 gold badge13 silver badges27 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 26

Use this :

public secondMethod(){
   this.firstMethod();
}

If you want to force the binding to the instance, use the => operator :

secondMethod= () => {
   this.firstMethod();
}
发布评论

评论列表(0)

  1. 暂无评论