1. #1
    Ext User
    Join Date
    Jun 2009
    Posts
    12
    Vote Rating
    0
    andyatmiami is on a distinguished road

      0  

    Default Why is scope declared in Ext.util.Event fire() method?

    Why is scope declared in Ext.util.Event fire() method?


    Below is the source code. I am a newbie in Ext (and more or less in javascript). I have been doing some extensive reading and trying to follow through the Ext source code, but I can't understand why scope is declared in this method when it never gets initialized nor used...

    Can anyone explain this behavior to me?

    fire : function(){
    var ls = this.listeners, scope, len = ls.length;
    if(len > 0){
    this.firing = true;
    var args = Array.prototype.slice.call(arguments, 0);
    for(var i = 0; i < len; i++){
    var l = ls[i];
    if(l.fireFn.apply(l.scope||this.obj||window, arguments) === false){
    this.firing = false;
    return false;
    }
    }
    this.firing = false;
    }
    return true;
    }

  2. #2
    Sencha - Community Support Team jay@moduscreate.com's Avatar
    Join Date
    Mar 2007
    Location
    DC Area =)
    Posts
    16,364
    Vote Rating
    81
    jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all

      0  

    Default


    Quote Originally Posted by andyatmiami View Post
    Below is the source code. I am a newbie in Ext (and more or less in javascript). I have been doing some extensive reading and trying to follow through the Ext source code, but I can't understand why scope is declared in this method when it never gets initialized nor used...

    Can anyone explain this behavior to me?

    fire : function(){
    var ls = this.listeners, scope, len = ls.length;
    if(len > 0){
    this.firing = true;
    var args = Array.prototype.slice.call(arguments, 0);
    for(var i = 0; i < len; i++){
    var l = ls[i];
    if(l.fireFn.apply(l.scope||this.obj||window, arguments) === false){
    this.firing = false;
    return false;
    }
    }
    this.firing = false;
    }
    return true;
    }


    Seems like you're a newb to posting code in forums too
    Code:
           fire : function(){
                var ls = this.listeners, scope, len = ls.length;
                if(len > 0){
                    this.firing = true;
                    var args = Array.prototype.slice.call(arguments, 0);
                    for(var i = 0; i < len; i++){
                        var l = ls[i];
                        if(l.fireFn.apply(l.scope||this.obj||window, arguments) === false){
                            this.firing = false;
                            return false;
                        }
                    }
                    this.firing = false;
                }
                return true;
            }
    Scope is not being declared, but rather referenced.

    if(l.fireFn.apply(l.scope||this.obj||window, arguments) === false){

    Basically, in English this means:

    if listener's method.apply return is equal to the value of and data type of false.

    Inside the apply call, there are two parameters being passed.

    The first is scope, and the second is arguments.

    Break down the scope, it's either listener.scope, this.object or ultimately window.

    Does this help/

  3. #3
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,545
    Vote Rating
    64
    Animal is a jewel in the rough Animal is a jewel in the rough Animal is a jewel in the rough

      0  

    Default


    The OP is correct. There is an unreferenced var declaration:

    Code:
           fire : function(){
                var ls = this.listeners, scope, len = ls.length;
                if(len > 0){
                    this.firing = true;
                    var args = Array.prototype.slice.call(arguments, 0);
                    for(var i = 0; i < len; i++){
                        var l = ls[i];
                        if(l.fireFn.apply(l.scope||this.obj||window, arguments) === false){
                            this.firing = false;
                            return false;
                        }
                    }
                    this.firing = false;
                }
                return true;
            }
    This still exists in the 2.* code, not the 3.0

  4. #4
    Sencha - Community Support Team jay@moduscreate.com's Avatar
    Join Date
    Mar 2007
    Location
    DC Area =)
    Posts
    16,364
    Vote Rating
    81
    jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all

      0  

    Default


    Yup missed it.

Thread Participants: 2