vendredi 26 février 2016

javascript module design pattern

I'm wondering what's the difference between this module declaration

( function( window, undefined ) {

  function MyModule() {
      this.myMethod = function myMethod() {
    };

    this.myOtherMethod = function myOtherMethod() {
      alert( 'my other method' );
    };

  }
    window.MyModule = MyModule;

   } )( window );

and this other one

var myModule = {
   myMethod: function () {
      console.log( 'my method' );
  },
   myOtherMethod: function () {
      console.log( 'my other method' );
  }
};

it could be helpful a proper OO programming analogy (if there's one it fits) :)

Aucun commentaire:

Enregistrer un commentaire