samedi 11 juillet 2020

How to export objects that are coming as arguments in a function in JavaScript (React)?

Let me explain the problem clearly I have a class which is in fileA looks like this

  // This is in FileA
import {twoClass} from "fileB"
class oneClass{
      public async functionA(varA){
              return value
   }
}
var twoClassObject = new twoClass()
var oneClassObject = new oneClass()
twoclassObject.funtionB(oneClassObject)

In fileB I have a twoClass which looks like

// This is in FileB No import in File B
export class twoClass{ 
  returnedObject: any;
  public funtionB(objectOfOneClass){
    this.returnedObject = objectOfOneClass
    console.log(await this.returnedObject.functionA(arg)) // prints the value in consloe
  }
}

As I am exporting this class I should be able to access it wherever I import the class right? But in fileC if I do this

// This is in FileC only should import File B but not File A
 import {twoClass} from 'fileB'
 var twoClassObj = new twoClass()
 console.log(await twoClassObj.returnedObject.functionA(arg))  // gives me an error TypeError: Cannot read property 'functionA' of undefined

Aucun commentaire:

Enregistrer un commentaire