dimanche 18 octobre 2015

methods calling methods inside object

i would like to know if there is a name for the pattern (is a pattern?) that i use. For example, instead of use like this:

var MyFakeClass = function(propertie) {
 this.propertie = propertie

 this.init();
};

MyFakeClass.prototype.method = function() {
 // something here
};

var instanceOfFakeClass = new MyFakeClass('propertie');
instanceOfFakeClass.method();

I do as follow:

var MyFakeClass = {
 init: function(propertie) {
  this.propertie = propertie;
  this.method();
 },

 method: function() {
  // something here
 }
};

MyFakeClass.init('propertie');

So, the init method calls the method, i don't need call from the outside.

Thanks.

Aucun commentaire:

Enregistrer un commentaire