PDA

View Full Version : listener functions



RamR
30 Oct 2009, 1:49 AM
Hi,

Since i am new to Ext, I cant figure out the following:
following is the part of code where my ext component is declared. and myFunction is the function tht i wish to execute on the 'check' event.



listeners:
{
check: myFunction()
}



After the component is fully configured I've written myfunction.



function myFunction()
{
.....
}



Is this the appropriate way to do it? or tings are diff in Ext. I also read abt createDelegate, when do u really need to create delegate?

smit_al
30 Oct 2009, 4:15 AM
You should check the doc's (http://www.extjs.com/deploy/dev/docs/) for valid listeners of an object. They are under "Public Events".

Animal
30 Oct 2009, 4:58 AM
Hi,

Since i am new to Ext, I cant figure out the following:
following is the part of code where my ext component is declared. and myFunction is the function tht i wish to execute on the 'check' event.



listeners:
{
check: myFunction()
}



After the component is fully configured I've written myfunction.



function myFunction()
{
.....
}



Is this the appropriate way to do it? or tings are diff in Ext. I also read abt createDelegate, when do u really need to create delegate?

Read your code.

What is the check property being SET TO when that object is CREATED?

You will have to imagine you are the Javascript runtime being asked to perform the code.

VinylFox
30 Oct 2009, 5:01 AM
Because the parenthesis are on your function name when adding it to this event, it is executing immediately and returning whatever your returning from your function to be run on that event happening.

Im guessing your function does not return another function, and what you really want to do is this:


listeners:
{
check: myFunction
}

Mike Robinson
30 Oct 2009, 6:43 AM
In the strange world of JavaScript:



myFunction is a reference to the function itself.
new myFunction creates a new instance of the function itself (a "closure")
myFunction() is a call to the function, which produces its result.


It takes a little getting used to.

You also need to be mindful of "what happens when," and what this refers to at various times. :((

Animal
30 Oct 2009, 6:47 AM
A little clearup.

Using "new" before a reference to a function that exists, invokes that function, but as a constructor.

It creates an object containing any prototype assigned to that function, and that becomes the "this" reference.

That's why Ext.Panel is just a function.

You invoke is as a constructor by calling it using new Ext.Panel