Contraindications in IIFE's

2

Is there any contraindication to using IIFE's within the context of an object?

For example, in the properties begin and created I make the function auto-execute to set the properties at the moment of instantiation of the variable.

Example:

var example = {
                example_id: scope.id,
                //Formating date to US
                begin: (function () {
                    var dateBr = scope.begin;
                    var dateUs = dateBr.split('/').reverse();
                    return dateUs.join('-');
                }()),
                period: scope.period,
                created: (function () {
                    var d = new Date();
                    var curr_day = d.getDate();
                    var curr_month = d.getMonth() + 1; //Months are zero based
                    var curr_year = d.getFullYear();
                    var curr_hour = d.getHours();
                    var curr_min = d.getMinutes();
                    var curr_sec = d.getSeconds();
                    return curr_year + "-" + curr_month + "-" + curr_day + " " + curr_hour + ":" + curr_min + ":" + curr_sec;
                }())
            };

I would like to know if using IIFE's can cause a problem?

    
asked by anonymous 31.03.2015 / 15:56

1 answer

3

No, I do not see any problem doing this. On the contrary, there are advantages, since you are not leaking variables to the global scope.

    
31.03.2015 / 16:08