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

119
Views
Access variable inside a function in another class

Is it possible with vanilla JS to access a let that was defined inside a function that's inside a class, from another class?

A non-functional attempt

// file-1.js
export default class myClass1 { 
  function myFunction(){
    let myVariable = 'Hello'
  }
}

// file-2.js
import myClass1 from "./file-1";

export default class myClass2 { 
  function printClass1(){
    // Print 'Hello'? 
    console.log(myClass1.myFunction().myVariable)
  }
}

I could find many answers on how it's done for other languages like C# and Python, but not for Vanilla Javascript

about 4 years ago · Juan Pablo Isaza
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!