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

158
Views
Javascript Command Pattern Logic

I'm reading Addy Osmani's 'Learning JavaScript Design Patterns' book. More precisely, a similar example is given in the book:

(function(){
  var Manager = {
    foo: function (param) {
      /*...*/
    },
    bar: function (param) {
      /*...*/
    }
  }
})();

The goal is to be able to do this:

Manager.execute("foo",param);

So the book shows this implementation:

Manager.execute = function ( name ) {
  return Manager[name] && Manager[name].apply( Manager, [].slice.call(arguments, 1) );
};

I've read this question on stackoverflow, but there are obvious changes from the example presented in the book. However I cannot understand how CarManager should be initialized and how it can work using that IIFE, since there is a closure with respect to all the functions of the CarManager itself. Why is this IIFE used in the book? Is this a mistake?

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!