如何从打字稿中的其他类访问私有类变量(react-redux应用程序)

时间:2019-04-23 12:54:20

标签: javascript typescript

我有一个带有cachedData变量的类。它是一个私有变量。 此变量(cachedData)从其他类更新。我无法创建静态方法,因为无法在静态方法内执行this.cachedData。但我也希望其他类更新此变量。我该如何实现?

      class myClass implements X{

      private cachedData:Array<entity>;

      cacheResponseData = ( val ):void => {
       this.cachedData = val;
       }

       clearSourceData = ():void => {
         this.cachedData = null;
       }

      }


      class OtherClass extends Y {

        constructor(
        dataProvider: QueryablePagedDataProvider<ReportingEntity>,
       ){
        super(dataProvider, DataStoreMode.SINGLE_PAGE);
       }

       someMethod()
       {
        // I need to update the cachedData in this method from myClass

       }


       }

0 个答案:

没有答案