Results 1 to 2 of 2

Thread: Function.prototype.createBindInterceptor

  1. #1
    Ext User
    Join Date
    Dec 2007
    Location
    italy
    Posts
    120

    Default Function.prototype.createBindInterceptor

    Hi guys...
    I created a new version of Function.prototype.createInterceptor that pass to the original function the returned form of intercepting function instead of original arguments.
    As in the original createInterceptor, if the passed function will return false, original function won't be called

    Usage example:

    PHP Code:
    var myFunction = function(name) {
      
    alert("My name is " name);
    }
    var 
    myInterceptingFunction myFunction.createBindInterceptor(new Function(name) {
      return [
    name.toUpperCase()];
    });

    myFunction("alberto"); //will alert "alberto"
    myInterceptingFunction("alberto"//will alert "ALBERTO" 


    Here's the code:

    PHP Code:
    Function.prototype.createBindInterceptor = function(fcnscope){
        if(
    typeof fcn != "function"){
            return 
    this;
        }
        var 
    method this;
        return function() {
            
    fcn.target this;
            
    fcn.method method;
            var 
    result fcn.apply(scope || this || windowarguments);
            if(
    result === false){
                return;
            }
            return 
    method.apply(this || windowresult || arguments);
        };

    Hope it will be useful to someone

  2. #2

    Default

    Good!To Be Worthy of learning!

Posting Permissions

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