jeudi 26 novembre 2015

Initialize factory method

Snippet of my object creation:

object = function ()
{
  var private = 'Yes.';

  var pub = {
    sayHello: function () {
      return isThisRealLife();
    }
  }

  function isThisRealLife() {
    return private + ' ' + 'Hello world!';
  }

  return pub;
}

What would be the best solution (minor error-prone) to initialize this?

Ideias:

  • Create a init method in pub -> object().init('foobar').
  • object = function (myVar) -> object('foobar').
  • Make object a IIFE with init method -> object.init('foobar').

Aucun commentaire:

Enregistrer un commentaire