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

232
Views
Javascript function Arguments object becomes the current webpack module magically?

I'm building a React application w/ Redux and in the mapDispatchToProps function - I'm using the pattern below.

const mapDispatchToProps = (dispatch) => {
  debugger
  Object.keys(actions).forEach(key => {
    var functionObj = actions[key];
    actions[key] = () => {
      debugger
      var zz = Array.prototype.slice.call(arguments);
      dispatch(functionObj.apply(null,zz));
    }
  });

  return actions;
}

Whats driving me bananas is that the arguments object is what I expect it to be (Array like object with the parameters bla bla) except when I "use" it in any way. By "use" I mean:

Assign it to something (like var zz above) OR pass it to a function. When I "use" the arguments object - it magically becomes the current Webpack module that I am currently in.

Does anyone know anything about this? Am I crazy??

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

This is caused by the fact that arrow functions do not provide an arguments object. So you are referencing the module wrapper function, which is the nearest non-arrow function.

You can fix this by using rest parameters instead. Good riddence! Rest parameters are a true array and do not need to be converted with any Array#slice() nonsense.

Below is an example, where I also used the spread operator to avoid the need to use Function#apply(), since you don't seem to need any special this value.

const mapDispatchToProps = (dispatch) => {
  debugger
  Object.keys(actions).forEach(key => {
    var functionObj = actions[key];
    actions[key] = (...zz) => {
      debugger
      dispatch(functionObj(...zz));
    }
  });

  return actions;
}
over 4 years ago · Santiago Trujillo 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!