0

I'm a bit new to TypeScript but know JavaScript from before. I have my code for a wheel mini-game for my app and I get the following error on my console.

this.easeOut is not a function

The code is the following (only what is important to the problem I think):

spin() {
  const spinAngleStart = Math.random() * 10 + 10;
  this.spinTime = 0;
  this.spinTimeTotal = Math.random() * 3 + 4 * 1000;
  this.rotateWheel(spinAngleStart);
}

rotateWheel(spinAngleStart: number){
  this.spinTime += 30;
  if(this.spinTime >=  this.spinTimeTotal) {
    this.stopRotateWheel();
    return;
  }
  *const spinAngle = spinAngleStart - this.easeOut(this.spinTime, 0, spinAngleStart, this.spinTimeTotal);*
  this.startAngle += (spinAngle * Math.PI / 180);
  this.drawRouletteWheel();
  console.log(this.spinTimeTotal);
  console.log(this.spinTime);
  this.spinTimeout = setTimeout(this.rotateWheel, 30);
 } 

easeOut(t, b, c, d) {
   const ts = (t /= d) * t;
   const tc = ts * t;
   console.log(ts);
   console.log(tc);
   return (b+c * (tc + -3*ts + 3*t));
  }

As you can see easeOut() does exists inside the same hierarchy of my rotateWheel() function and everything else if not sending any errors, so I do not why it sends an error.

the error is sent to the line with the asterisks

1 Answer 1

2

You either want setTimeout(() => this.rotateWheel(), 30) or setTimeout(this.rotateWheel.bind(this), 30);. Otherwise, when rotateWheel is called, this is bound to the window object (or global object in node).

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

2 Comments

Thanks so much, it is now fixed! :D
@OmarTorres please accept this as your answer. So nobody need to look for helping in this thread

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.