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

315
Views
Uncaught ReferenceError: Cannot access 'Sprite' before initialization

I'm currently programming a web game and I'm stuck here, could someone help me? I've tried different ways but I've been stuck here for a few hours so I thought I'd write here, I'm a junior programmer and I'm using this page for the first time, if I've described something wrong I apologize.

Uncaught ReferenceError: Cannot access 'Sprite' before initialization

const backgorund = new Sprite({
  position: {
    x: 0,
    y: 0
  },
  imageSrc: './img/background.png'
})

class Sprite {
    constructor({position, velocity, imageSrc}) {
        this.position = position
        this.velocity = velocity
        this.width = 50
        this.height = 150
        this.image = new Image()
        this.image.src = imageSrc
    }
    draw() {
      c.drawImage(this.image, this.position.x, this.position.y)

    }
    update() {
        this.draw()
    }
  }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You need to initialize a class before use. Move your class declaration on top:

class Sprite {
  // ...
}

const backgorund = new Sprite({
   // ...
})
about 4 years ago · Juan Pablo Isaza Report
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!