0

I am attempting to create a JavaScript Text Animation but i am getting particleArray is undefined i am not sure how to resolve the issue i have tried moving the code from the mounted method since it would load before being defined but same results.

export default {
    data : function (){

         return {
             particleArray: null,
             x:null,
             y:null,
             radius: 150,
             vuedata: null,
        }

    },
class Particle{
           constructor(x, y){
              this.x = x + 100;
              this.y = y;
              this.size = 3;
              this.baseX = this.x;
              this.baseY = this.y;
              this.density = (Math.random() *30) + 1;
        }


           draw(){
                ctx.fillStyle = '#fff';
                ctx.beginPath();
                ctx.ard(this.x, this.y, this.size,0,Math.PI * 2);
                ctx.closePath();
                ctx.fill();

           }
       }

        function init(){
            this.particleArray = [];
            particleArray.push(new Particle(50,50));
        }
0

1 Answer 1

1

The answer is this.particleArray.push(new Particle(50,50));

this.particleArray = []; assigns the data property particleArray the value [].

particleArray.push(new Particle(50,50)); attempts a method on a local variable that does not exist.

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.