a simple way to solve this is
initialize: function(){
var self = this;
this.togglers = $$('ul');
this.togglers.addEvent('click',function(){
//this reference ul
var childContainer= this.parentNode.getElement('ul');
//self reference the class
self.myAlert(childContainer);
})
},
On Fri, Jul 24, 2009 at 6:35 PM, Serkan T <[email protected]> wrote:
>
> hi,
>
> I have problems with binding and this references in a function. i.e
> using two different this reference in a function . Here is the case:
>
> var myNewClass = new Class({
> options: {
> /*bla bla*/
> },
> initialize: function(){
> this.togglers = $$('ul');
> this.togglers.addEvent('click',function(){
> var childContainer= this.parentNode.getElement('ul');
> this.myAlert(childContainer);
> })
> },
> myAlert: function(message){
> alert(message)
> }
> })
>
>
> Browser returns an error saying this.myAlert is undefined
>
> I know I can overcome this by using .bind(this) to addEvent function
> but in this case this.parentNode becomes undefined.
>
> in fact this references two different things for this.parentNode and
> this.myAlert
>
> I'm sure there is a simple solution for this but cant see it actually
>
> Thanks for your help
--
fax : (+33) 08 26 51 94 51