0

how can i call getting function on this class? for example i have this kind of button for example if i have a class like this

javascript.js

class Hero {
   a=1;
   b=2;
}

class BokunoHero extends Hero {

   gettingValue(){
     return alert(a + b);
   }
}

functioncall.html

<button id="clickmeplease" onclick="whatinsidehere?"></button>

what inside the onclick on onclick button

1 Answer 1

1

use a function to create an instance and call the method :

const getvalue = () => {
  let MyBokunoHero= new BokunoHero();
  console.log(MyBokunoHero.gettingValue());
};

class Hero {
  constructor() {
    this.a = 1;
    this.b = 2;
  }
}

class BokunoHero extends Hero {
  constructor() {
    super();
  }
  gettingValue() {
    return this.a + this.b;
  }
}
<button id="clickmeplease" onclick="getvalue()">CLICK ME</button>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.