In this post we will have a look at the spaghetti code created by functions and how to avoid them. First lets quickly go through why this is a cause of concern. Problems with Function Spaghetti Code Variables/ functions are added to the global scope The code is not modular There's potential for duplicate function names Difficult to maintain No namespace sense. Let's take for example the following set of functions and check whats the issue with them. // file1.js function saveState(obj) { // write code here to saveState of some object alert('file1 saveState'); } // file2.js (remote team or some third party scripts) function saveState(obj, obj2) { // further code... alert('file2 saveState"); } Now the problem here is if your application is using saveState() then the execution of saveState() which one to call is determined by the script loading. The later script overrides same functions already defin...
My technical notes, the lessons learned, the mistakes commited, the rectification made and my journey towards understanding the technology, life and the hidden power in our own little universe.