override a Javascript function inside another function? - Javascript Function

Javascript examples for Function:Function Nest

Description

override a Javascript function inside another function?

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  ww  w .j a  v  a 2 s.  c  om
var parentMethod = {
  someOtherMethod: function() {
    console.log("Am someone")
  },
  childMethod: function() {
    console.log("Am Child")
  }
};
parentMethod.childMethod();
parentMethod.childMethod = function() {
  console.log("Am Child New")
};
parentMethod.childMethod();
    }

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

Related Tutorials