Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

159
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda