javascript - How to correctly use multiple initialization functions? -
i trying understand whether or not concept behind using multiple initialization functions bad practice. initialization function mean either of following:
$(document).ready(function(){ //... code here } (function(){ //.... code here })();
time , time again have seen multiple initialization functions being used , thought bad practice, wrong?
based on that, care enlighten me whether or bad practice use multiple initialization functions?
edit: removed irrelevant example of bad use of closure , encapsulation.
your suspicion correct in it's idea organize code when can.
centralizing initialization functions makes easier developer figure out statements being executed @ given time. facilitates debugging , becomes increasingly important when multiple developers working on same code.
perhaps consider doing this:
$(document).ready(function () { function findlionelrichie() { console.log('found lionel richie'); } function findwhomeverelseneedsfinding() { console.log('found others'); } (function initialize() { findlionelrichie(); findwhomeverelseneedsfinding(); })(); });
that being said, cannot avoided (for example, when calling functions external libraries). try keep organized can on end, however.
Comments
Post a Comment