Reputation:
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.
Upvotes: 0
Views: 37
Reputation: 707228
There are many different ways to describe it and probably no single moniker that is always used for that:
"Singleton" is probably a useful word here because it describes an object of which there is only intended to be one of. There are many different possible ways to declare a singleton. Your declaration is one such way.
"Statically declared" differentiates your second option from the first one with a constructor that is created with new
.
Upvotes: 1