-
30 Jun 2009 8:05 AM #1
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;
}
-
4 Jul 2009 9:06 AM #2Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- Frederick MD, NYC, DC
- Posts
- 16,169
- Vote Rating
- 28
Seems like you're a newb to posting code in forums too
Scope is not being declared, but rather referenced.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; }
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/
Jay Garcia @ModusJesus || Modus Create co-founder
Ext JS in Action author
Sencha Touch in Action author
Get in touch for Ext JS & Sencha Touch Touch Training
We are also working on Video-based Sencha Touch training: Check it out here.
-
4 Jul 2009 11:18 PM #3
The OP is correct. There is an unreferenced var declaration:
This still exists in the 2.* code, not the 3.0Code: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; }Search the forum: http://www.google.com/coop/cse?cx=01...%3Az7of1ufqccu
Read the docs too: http://extjs.com/deploy/dev/docs/
Scope: http://extjs.com/forum/showthread.ph...642#post257642
-
5 Jul 2009 4:19 AM #4Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- Frederick MD, NYC, DC
- Posts
- 16,169
- Vote Rating
- 28
Yup missed it.

Jay Garcia @ModusJesus || Modus Create co-founder
Ext JS in Action author
Sencha Touch in Action author
Get in touch for Ext JS & Sencha Touch Touch Training
We are also working on Video-based Sencha Touch training: Check it out here.


Reply With Quote