Skip to main content
formatting, typos, removed cruft
Source Link
Matt Ball
  • 358.5k
  • 102
  • 650
  • 716

Can I intercept direct method calla function called directly?

In this code I a created a function called someFunction. thenThen I Modifiedmodified Function.prototype.apply and call methods. soSo instead of my function code is working I am runingrunning my interception code. (which shows an alert). But neighterneither "call" nor "apply" intercepts direct method call. isIs it possiple to intercept this?

<html>
    <head>
     <script type="text/javascript" src="logger.js"></script>
    <script type="text/javascript">
     Function.prototype.call = function(){alert("call");};
     Function.prototype.apply = function(){alert("apply");};
     function someFunction(){}
     logger.enableLog = true;
     window.onload = function(){
      someFunction.call(this); //call alert is shown
      someFunction.apply(this); //apply alert is shown
      someFunction(); //how can I intercept this.?
     }
    </script>
    </head>
    <body>
    </body>
    </html>

Can I intercept direct method call

In this code I a created a function called someFunction. then I Modified Function.prototype.apply and call methods. so instead of my function code is working I am runing my interception code. (which shows an alert). But neighter "call" nor "apply" intercepts direct method call. is it possiple to intercept this?

<html>
    <head>
     <script type="text/javascript" src="logger.js"></script>
    <script type="text/javascript">
     Function.prototype.call = function(){alert("call");};
     Function.prototype.apply = function(){alert("apply");};
     function someFunction(){}
     logger.enableLog = true;
     window.onload = function(){
      someFunction.call(this);//call alert is shown
      someFunction.apply(this);//apply alert is shown
      someFunction();//how can I intercept this.
     }
    </script>
    </head>
    <body>
    </body>
    </html>

Can I intercept a function called directly?

In this code I created a function called someFunction. Then I modified Function.prototype.apply and call methods. So instead of my function code is working I am running my interception code (which shows an alert). But neither "call" nor "apply" intercepts direct method call. Is it possiple to intercept this?

Function.prototype.call = function(){alert("call");};
Function.prototype.apply = function(){alert("apply");};
function someFunction(){}
window.onload = function(){
    someFunction.call(this); //call alert is shown
    someFunction.apply(this); //apply alert is shown
    someFunction(); //how can I intercept this?
}
Source Link
yilmazhuseyin
  • 6.6k
  • 4
  • 36
  • 38

Can I intercept direct method call

In this code I a created a function called someFunction. then I Modified Function.prototype.apply and call methods. so instead of my function code is working I am runing my interception code. (which shows an alert). But neighter "call" nor "apply" intercepts direct method call. is it possiple to intercept this?

<html>
    <head>
     <script type="text/javascript" src="logger.js"></script>
    <script type="text/javascript">
     Function.prototype.call = function(){alert("call");};
     Function.prototype.apply = function(){alert("apply");};
     function someFunction(){}
     logger.enableLog = true;
     window.onload = function(){
      someFunction.call(this);//call alert is shown
      someFunction.apply(this);//apply alert is shown
      someFunction();//how can I intercept this.
     }
    </script>
    </head>
    <body>
    </body>
    </html>