call or autoload another method if calling method is undefined - Javascript Object

Javascript examples for Object:Object Method

Description

call or autoload another method if calling method is undefined

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(){/*w  w w .j  av  a  2  s .  c om*/
function MyObject() {
   this.methodDefined = function() {
        console.log('Mom was called.');
    }
   this.exceptionHandler = function() {
        console.log('Catch all was called');
    }
}
q = new MyObject();
q.methodDefined();
q.methodNotDefined ? q.methodNotDefined() : q.exceptionHandler();
    }

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

Related Tutorials