My javascript gets included multiple times with the script tag, like so:
<script src='code.js></script> <script src='code.js></script> <script src='code.js></script>
Right now I have this code inside code.js to make my code run only once without overwriting my namespaces:
if(typeof _ow == 'undefined' ){ _ow = {}; // code in here will only run once _ow.Auth = (function(){ })(); _ow.Template = (function(){ })(); }
Is there any better structure I could use to make my code only run once?
Are you familiar with Crockford’s Javascript Module Pattern?
A slight variation on how to prevent overwriting the namespace: