Computer Science, asked by acdbr991, 1 year ago

How to access properties of a class from another class in javascript?

Answers

Answered by clue
0

Hello here is the right syntax;

To make the method static :

class One {

 static write(){

   console.log("Yes! I did!");

 }

}

class Two {

  tryingMethod(){

    One.write();

  }

}


For A non-static case:

class One {

 write(){

   console.log("Yes! I did!");

 }

}

class Two {

  constructor() {

      this.one = new One();

  }

  tryingMethod(){

    this.one.write();

  }

}

var x = new Two();

x.tryingMethod();

Similar questions