Untitled

mail@pastecode.io avatar
unknown
javascript
3 years ago
715 B
2
Indexable
Never

class B {
  constructor(data) {
    this._data = [...data];
  }
 getValue(idx) {
   return this.data[idx];
 }
 doSomething() {
   const valA = this.getValue(0);
   const valB = this.getValue(2); 
   const res = valA + valB; 
   return res;
 } 
}
 

/*--------------------------------*/

import ClasseB from 'classeB';

class ClassA {
  _data = [1,2,3,4,5]; 

  constructor(){
    this._myClassB =  new ClassB(this._data);
  }

  init() {
    const element = document.querySelector('#button');
    element.addEvenListener('click', this.clickHandler.bind(this)); 
  }

 clickHandler(evt) {
    const target = evt.currentTarget;
    /* .... */
    const res = this._myClassB.doSomething();   
    this.update();
 }
}