2
Is there any contraindication using IIFE’s within the context of an object?
For example, in the properties begin
and created
i do the auto run function to set the properties at the time of variable instantiation.
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 the IIFE so can bring some problem?
Thanks Friend, I already confirm the answer face, because I know you a long time here from the OS and it is not the first time that helps me. Hugção.
– Marcelo Aymone
You’re welcome. I may be wrong too, but I’ve never really seen any contraindications to this practice.
– bfavaretto