Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

279
Views
ES6 class - accessing instance variables

I am working on a webapp where I have pages with multiple horizontally scrolling panels. I want to handle the horiziontal scroll via my own vanilla JS code. Given that I need to do this many times over I thought I would wrap that functionality in an ES6 class. My effort are along the following lines

class HoriScroll 
{
 constructor(id)
 {
  this.target = document.getElementById(id);
  this.target.addEventListener('touchstart',this.slideStart,{passive:true});
  this.target.addEventListener('touchmove',this.slideMove,{passive:true});
  this.target.dataset.startX = null;
  this.target.dataset.startTime = null;
  this.target.dataset.movePending = false;
 }

 slideStart(e)
 {
  if (1 === e.changedTouches.length) 
  {
   this.dataset.startX = e.changedTouches[0].screenX;
   this.dataset.startTime = Date.now();
  } 
 }
}

While I will be able to get things working this way what bothers me is the rather clumsy way I am recording startX, startTime etc - as attributes of the dataset of the horizontal scroll target HTML element. I ended up doing this since I cannot work out a way to access instance variable values in the class. For instance in slideStart this refers to the HTML element instance, not the HoriScroll class instance.

How, if at all, can this be done.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!