TypeScript compiles a class something like:
var UrlProvider = (function(){
//tons of logic in here that only needs to be performed once for each UrlProvider instance
function UrlProvider(baseUrl){
var baseRequest = {
get: function(){return baseUrl;},
update: function(){return baseUrl;},
delete: function(){return baseUrl;}
};
var documents = function(){
var context = '/documents/';
return{
get: function(){return baseRequest.get() + context;},
post: function(){return baseRequest.post() + context;},
delete: function(){return baseRequest.delete() + context;}
}
};
var editors = function(){
var context = '/editors/';
return{
get: function(){ return baseRequest.get() + context; },
post: function(){ return baseRequest.post() + context; },
delete: function(){ return baseRequest.delete() + context; }
}
}
}
return UrlProvider;
})();
Is there any benefit to putting logic outside of the UrlProvider constructor, but inside the closure of the outer IIFE? My thinking was that perhaps if we needed a remote service or some other expensive process to create UrlProviders that could possibly be better placed in the outer closure vs. the constructor of the UrlProvider? Is this correct? IS there any benefit to putting logic in outside the constructor, but inside the IIFE?