List Info

Thread: Issue with 'this' after 1.6 upgrade




Issue with 'this' after 1.6 upgrade
user name
2007-12-27 06:12:24
Hi,
I'm having an issue with class variables, after upgrading to
1.6

in the initialize function i have
this.currentItem = '';

The class method switchTo is called by a mouseover event.
this.currentItem is then changed to for example
'3SE0723W-25-30'

Then class method resetImage is called by a mouseout event.
this.currentItem has not been touch during this time... yet
in the
resetImage method the value of this.currentItem is false...
?

Thanks
Rob
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffsgooglegroups.com
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=
en
-~----------~----~----~----~------~----~------~--~---


Re: Issue with 'this' after 1.6 upgrade
user name
2007-12-27 06:26:53
Just 1 more thing...
It shouldn't matter if the class method  is being called
from within a
method within another class.
I have declared the class instances globally.

this is a simplified version of my class:
------

var imageSwapper = Class.create({
	initialize: function()
	{
		this.currentItemCode = '';
	},
	switchTo: function(variant,toselect)
	{
		this.currentItemCode = '3SE0723W-25-30';
	},
	resetImage: function()
	{
		if(currentItemCode)
		{
			alert('image code set');
		}
		else
		{
			alert('no item code');
		}
	}
});

var image_swapper;
function initImageSwapper() { image_swapper = new
imageSwapper(); }
Event.observe(window, 'load', initImageSwapper);

------


On Dec 27, 12:12 pm, Rob <rald...gmail.com> wrote:
> Hi,
> I'm having an issue with class variables, after
upgrading to 1.6
>
> in the initialize function i have
> this.currentItem = '';
>
> The class method switchTo is called by a mouseover
event.
> this.currentItem is then changed to for example
'3SE0723W-25-30'
>
> Then class method resetImage is called by a mouseout
event.
> this.currentItem has not been touch during this time...
yet in the
> resetImage method the value of this.currentItem is
false... ?
>
> Thanks
> Rob
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffsgooglegroups.com
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=
en
-~----------~----~----~----~------~----~------~--~---


Re: Issue with 'this' after 1.6 upgrade
user name
2007-12-27 06:27:55
Just 1 more thing...
It shouldn't matter if the class method  is being called
from within a
method within another class.
I have declared the class instances globally.

this is a simplified version of my class:
------

var imageSwapper = Class.create({
        initialize: function()
        {
                this.currentItemCode = '';
        },
        switchTo: function(variant,toselect)
        {
                this.currentItemCode = '3SE0723W-25-30';
        },
        resetImage: function()
        {
                if(this.currentItemCode)
                {
                        alert('image code set');
                }
                else
                {
                        alert('no item code');
                }
        }

});

var image_swapper;
function initImageSwapper() { image_swapper = new
imageSwapper(); }
Event.observe(window, 'load', initImageSwapper);

On Dec 27, 12:12 pm, Rob <rald...gmail.com> wrote:
> Hi,
> I'm having an issue with class variables, after
upgrading to 1.6
>
> in the initialize function i have
> this.currentItem = '';
>
> The class method switchTo is called by a mouseover
event.
> this.currentItem is then changed to for example
'3SE0723W-25-30'
>
> Then class method resetImage is called by a mouseout
event.
> this.currentItem has not been touch during this time...
yet in the
> resetImage method the value of this.currentItem is
false... ?
>
> Thanks
> Rob
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffsgooglegroups.com
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=
en
-~----------~----~----~----~------~----~------~--~---


Re: Issue with 'this' after 1.6 upgrade
user name
2007-12-27 08:50:33
I can't think of anything different in 1.6 (in this context)
except
that event callbacks are now bounded to their elements. Even
so, this
hardly seems to be a problem, since I'm sure you are binding
your
callbacks the proper way.

$('foo').observe('click', function() {
  this.addClassName('active'); // <= "this" was
not guaranteed to
refer to $('foo') in <1.6
})

$('foo').observe('click', this.resetImage.bind(this)); //
<= should be
fine when used in instance method
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffsgooglegroups.com
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=
en
-~----------~----~----~----~------~----~------~--~---


[1-4]

about | contact  Other archives ( Real Estate discussion Medical topics )