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

173
Views
Is there a way to access the "arguments" object inside of a closure?

I have a closure, and I want to access the arguments to the closure from inside the closure. Is this possible?

function outerFunction (param1, param2) {
  // Returns [param1, param2, [param1, param2]]
  return function innerFunction () { return [param1, param2, arguments] }
}

// [1, 2, [1, 2]]
console.log(outerFunction(1, 2)(3, 4));

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

0

arguments is a special beast, and follows different rules in sloppy mode than in strict mode. It is array-like, but not a real array. But it is not necessary to use it. Just use rest parameter syntax:

function outerFunction (param1, param2) {
  return function innerFunction (...args) { 
    return [param1, param2, args];
  };
}

let result = outerFunction(1, 2)(3, 4);
console.log(result); // [1, 2, [3, 4]]

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!