View Full Version : scope and EventManager
mcohnen
13 Sep 2007, 3:43 AM
Hi, I have been searching through the forums and documentations, but i still have problems to know what the scope is EventManaget.onWindowResize();
I did like in an example in demos:
var MyResize = function(){
alert("hola");
}
Ext.EventManager.onWindowResize(MyResize.init,MyResize,true);
But it throws following javascript error:
l.fireFn has no properties
What am i doing wrong?
By the way, i have all my code in Ext.onReady(function() {}
I suppose this is not the best way of using extJs. So what should be the best? A var (mysite) for each site, and Ext.EventManager.onDocumentReady(mysite.init,mysite) to call in every site?
Thank you !
Animal
13 Sep 2007, 3:53 AM
You are passing MyResize.init to use as a function.
Does the MyResize object (which I can see that you have from your posted code) have a property called "init" which is a function?
mcohnen
13 Sep 2007, 3:56 AM
var MyResize = function(){
var init = function (){
alert("hola");
}
}
Ext.EventManager.onWindowResize(MyResize.init,MyResize,true);
This is my simply code. Debugging with Firebug shows me that there is no value for the fire function.
Thank you very much Animal, you are helping me a lot! hope i can help someone when i got some experience with this awesome framework! :D
Animal
13 Sep 2007, 3:57 AM
OK, and does MyResize have a property inside it, called "init" which is a function?
mcohnen
13 Sep 2007, 3:59 AM
It is written like in my preivous post. MyResize has a property named var init, which is a function.
Edit:
This is working:
var MyResize ={
init: function (){
alert("hola");
}
}
Ext.EventManager.onWindowResize(MyResize.init,MyResize,true);
The demo example confused me ;)
So is it a good approach to have one class per site, with an init method, and call it when the site loads?
Thanks!
Animal
13 Sep 2007, 4:17 AM
Right, you should read your code. The demo does things for a different reason
var foo = function(){ return "whatever" };
means that foo is a function, not what the function returns, you have not called it.
While
var foo = function(){ return "whatever" }();
means that foo contains the results of that function.
That second way allows you to return an object which contains functions which have references to variables that only exist within the scope of the function. ie, an object with private data.
If you don't need thatm then don't use the pattern.
You don't need an object with an init function inside it. You just need a function.
mcohnen
13 Sep 2007, 4:36 AM
Dammit! You are right! i did not see ()!!! Now everything has sense again :D. Thanks a lot!
Powered by vBulletin® Version 4.1.5 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.