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

135
Views
Referencing a javascript object from within its declaration

Why is it possible to reference an object from within the object directly? For example:

var object = {
    prop1 : "Prop 1",
    prop2 : "Prop 2",
    func : _ => console.log(object)
}

object.func();

//output {prop1: 'Prop 1', prop2: 'Prop 2', func: ƒ}

Similarly I could do:

var object = {
    prop1 : "Prop 1",
    prop2 : "Prop 2",
    func : function() { console.log(this) }
}

object.func();

This will result in the same output as above. I am mainly trying to understand why it is legal to reference the variable name object from inside its declaration.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Attempts to access variables inside functions are not resolved until the function is called … which will be after the object is created.

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!