Hi,

Method B & C work, because you call the function and don't pass it to
blur().

Regards,
Markus

On 30 Jun., 20:18, Oltmans <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> I'm stuck in a situation where I need help. Any help will be highly
> appreciated. I've created an object, after creating the object, I'm
> assigning one of its functions to an event handler i.e. to onBlur
> event of Text-area. Problem is that when I try to access object
> properties from the handler function, I cannot access them in some
> cases and get a value of undefined. Here is the sample code that I'm
> trying
>
> METHOD A:
> ---------
> function TestObj(src, dest){
>
> this.src = src;
> this.dest= dest;
> this.count = 500;
>
> }
>
> TestObj.prototype.display=function(){
>
> //following displays 'undefined'
> alert("Source ="+this.src+", Destination ="+this.dest);
> //following also displays 'undefined'
> alert('Count ='+this.count);
>
> }
>
> and here is how I'm using the above (using JQuery)
>
> $(document).read(function(){
> var t=new TestObj(50,100);
> $("#tarea1").blur(t.display);
>
> });
>
> But when I do the following using Object literal , things seem to
> work
> OK
>
> METHOD B
> --------
>
> var TestObj={
>
> display:function(src,dest){
>
>         return function(){
>                 alert("Source ="+this.src+", Destination
> ="+this.dest);
>         }
>
> }
> };
>
> $(document).read(function(){
> //This works and I see values of 50 & 100 in the alert box
> $("#tarea1").blur(TestObj.display(50,100));
>
> });
>
> Amazingly following also works :)
>
> METHOD C:
> ---------
> function TestObj(){
>
> }
>
> TestObj.prototype.display=function(src,dest){
>
> return function(){
>         alert("Source ="+this.src+", Destination ="+this.dest);
>         }
>
> }
>
> and here is how I'm using the above (using JQuery)
>
> $(document).read(function(){
>
> var t=new TestObj();
>
> $("#tarea1").blur(t.display(5,10));
>
> });
>
> Actually, I want to go with the Function object approach mentioned
> under METHOD C, but I'm also trying to avoid the closure in " display
> " function as I've read on Internet that it can cause memory leaks in
> IE6. Any ideas on how to make METHOD C work while avoiding a closure.
>
> Also, if you can give a reason as to why METHOD A isn't working that
> will be highly appreciated.
> Thanks in advance.
>
> Regards,
> Oltmans

Reply via email to