Open CaryLandholt opened 9 years ago
Why would you want to eliminate public function or variable ? Anonymous function do not take more memory, then do not consume time. Outside of namespace issue what is the real disadvantage ? I use public function each time I think it makes the code easier to read and maintain, but I have no religion about it.
In the case of bzmDatePicker I could have simply embedded bzmDatePicker as an anonymous function of DatePicker.directive that itself could be an anonymous of angular.module('bzm-date-picker') but what would be the advantage ? I doubt it would be easier to understand or to debug and after minimizing it does increase size of more than 10 Bytes.
Are you ready to loose some easiness of readability and maintainability for 10 Bytes ?
It's not about readability. It's about polluting the global namespace. Best practice is to avoid it.
Polluting global name space with something that is prefixed by "bzm" does not loop a top priority for me, is it for you ?
To be clear, I mean the entire file should be surrounded in an IIFE. The code is fine.
yep - should be avoided
I'm probably to old to take care about this time of coding religion :)
I like to keep my code as simple and as basic as possible. Until someone will have show me some real technical advantage to anonymous function I doubt they will come on my priority list. It is not article like http://stackoverflow.com/questions/10273185/what-are-the-benefits-to-using-anonymous-functions-instead-of-named-functions-fo this one that are going to convince me
Now if you have some reference that show real performance improvement, I would be more than happy to change my mind.
It is considered a best practice....not "religion". That seems very condescending. If you want people to use your work in a complex environment then this should be something you care about.
@fulup-bzh your link is about anonymous vs names. This is not the argument. Avoiding global variables is best practice. There are many articles on the subject.
All you have to do is surround your final code:
(function() {
// code from https://github.com/fulup-bzh/DatePicker/blob/master/dist/bzm-date-picker.min.js
}());
I'm old too
Me too sigh
And as Cary stated, the code is good. Thanks for this.
You might be right but you still did not convince me enough to make this a priority :) This being said if one of you want to: fork, patch, test, ... I would be more than happy to merge you effort with my work.
This will eliminate the unneccessary public variable
bzmDatePicker
.http://benalman.com/news/2010/11/immediately-invoked-function-expression/