Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

160
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda