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

376
Views
js make later get window variable; don't init var until this var is called

I expect set window variable before its inner class defined, so I make following code

Object.assign(window, {
    get C2() {
        return C
    }
})

class C {

}

new C2()

but it raise Uncaught ReferenceError: Cannot access 'C' before initialization, I know put class C def before Object.assign can fix this err, but my confused is why following code cannot later get

Object.assign(window, {
        get C2() {
            return C
        }
    })
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The C class you name is actually referenced as soon as you call Object.assign, the get C2() property that is created contains a reference to C that must be known when Object.assign is called.

If the C class name is not known when Object.assign is called, then JS doesn't know what should be assigned.

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!