My question is about understanding a design pattern I encountered here.
Basically, we have the following IIFE:
!function(param1, param2, one, two, three) {
// do something usefull with <param1> and <param2>...
// ...and use <one>, <two> and <three> as local variables
one = function(...) {...};
two = 123;
three = document.createElement(...);
}(value1, value2);
One can see that some of its parameters are used as local variables only. They are undefined when the function is called.
Are there any differences with the (more readable) code below?
!function(param1, param2) {
// do something usefull with <param1> and <param2>...
// ...and use <one>, <two> and <three> as local variables
var one = function(...) {...};
var two = 123;
var three = document.createElement(...);
}(value1, value2);
Aucun commentaire:
Enregistrer un commentaire