Prevent an object, function or variable to be defined twice - Javascript Object

Javascript examples for Object:prototype

Description

Prevent an object, function or variable to be defined twice

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){/*from w  w w.  j a  v a 2  s. co m*/
window.foo = (window.foo || (function(){
  console.log("111");
  return true;
}()));
window.foo = (window.foo || (function(){
  console.log("222");
  return true;
}()));
    }

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials