Results 1 to 2 of 2

Thread: [4.0.1] Create function interceptor

    Thank you for reporting this bug. We will make it our priority to review this report.
  1. #1
    Ext JS Premium Member
    Join Date
    Mar 2007
    Posts
    61
    Vote Rating
    4
      0  

    Default [4.0.1] Create function interceptor

    Please forgive me if this does not end up being a bug. I have reached my ability/time limit of investigating this any further.

    The Ext.Function.createInterceptor function when used to intercept a static function (in my cast, Ext.util.History.add) does not seem to call the original function with the correct object.

    I have made a simple example to demonstrate that.

    The page will call the Ext.util.History.add function twice, then an interceptor is created, and then function is called. The block in the interceptor function will be executed correctly, but the when the original History.add function is called, it fails.

    Stepping through the add function, you will see that after the interceptor is called, the Window object is used to call the original add function.

    I'm not sure if this is a bug of the createInterceptor function or the History.

    Self contained example of the problem.
    Code:
    <html>
    <head>
        <title>ExtJs 4 - function intercept test</title>
        <!-- Ext includes -->
        <link rel="stylesheet" type="text/css" href="http://dev.sencha.com/deploy/ext-4.0.0/resources/css/ext-all.css" />
        <script type="text/javascript" src="http://dev.sencha.com/deploy/ext-4.0.0/ext-all-debug.js"></script>
        
    	<script type="text/javascript">
    
    		Ext.onReady(function() {
    	    
    		    Ext.util.History.init();
    		   
    		    Ext.util.History.add('atoken', true);
    		    
    		    alert("history added, see URL, a new history token will be added after this dialog is dismissed");
    		    
    		    Ext.util.History.add('anothertoken', true);
    		    
    		    var myInterceptor = Ext.Function.createInterceptor(Ext.util.History.add, function( tk , nodup){
    			if(console){console.info('interceptor function called with token: \''+tk+'\', calling original function History.add() (will fail)');}
    			return true;
    		    });
    		    
    		    myInterceptor('newtoken', true);
    		    
    		});
    	</script>
    </head>
    <body>
        <form id="history-form" class="x-hide-display">
        <input type="hidden" id="x-history-field" />
        <iframe id="x-history-frame"></iframe>
    </form>
    </body>
    </html>


  2. #2
    Ext JS Premium Member
    Join Date
    Mar 2007
    Posts
    61
    Vote Rating
    4
      0  

    Default

    Okay, the following change to the above code works.
    PHP Code:
    //var myInterceptor = Ext.Function.createInterceptor(Ext.util.History.add, function( tk , nodup){
                
    Ext.util.History.add Ext.Function.createInterceptor(Ext.util.History.add, function( tk nodup){
                if(
    console){console.info('interceptor function called with token: \''+tk+'\', calling original function History.add()');}
                return 
    true;
    }, 
    Ext.util.History);
                
    Ext.util.History.add('newtoken'true);
    //myInterceptor('newtoken', true); 
    The documentation says,
    If omitted, defaults to the scope in which the original function is called or the browser window.
    BUT! using another function such as 'myInterceptor= Ext.Function.createInterceptor ....' does not work even with the scope specified.
    PHP Code:
    var myInterceptor Ext.Function.createInterceptor(Ext.util.History.add, function( tk nodup){
                if(
    console){console.info('interceptor function called with token: \''+tk+'\', calling original function History.add()');}
                return 
    true;
     }, 
    Ext.util.History);
    myInterceptor('newtoken'true); 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •