Suppose we have following files:
Here app.js is responsible for invoking functions inside script1.js and script2.js and you will get below output in your console window as shown below:
Well, this happens because we have the same variable name in script1.js and script2.js in the global scope. This is the reason script2.js is overriding over script1.js
In order to fix this issue we will use the concept of the namespace as described below with the following changes made to these files:
In the above two files, we have created an object and then assigned names to the name variable. In this way, we have prevented any overriding issue.
In the above file, we have used a new function name and that will get invoked while running program and your console window will look as shown below:
Please Login to comment...