I am trying to use pre-existing functions in a new prototype class but am having some trouble with binding. When I call a function within a function it says that one of my class variables is undefined. I have defined the class variable correctly I think:
var DropDown = Class.create({ initialize: function(date, appt_counter, times, edit_or_add) { this.start_drop_id = "start_drop_" + date + "_" + appt_counter; }) Then in the following outside function, start_drop_id is errored as being undefined: DropDown.prototype.show_block = function(element_id, element) { if(document.getElementById(element_id).style.display == "block") { outsideOf = null; $(document.body).descendants().invoke ('stopObserving','click',this.outside); //stopObserving the outside request as we have finished document.getElementById(element_id).style.display = "none"; } else { outsideOf = element_id; document.getElementById(element_id).style.display = "block"; $(document.body).descendants().invoke ('observe','click',this.outside); element.stopObserving('click',this.outside) //need to then stop this from observing the outside - ie requires it at least }; }; DropDown.prototype.outside = function(event) { //alert(this.outsideOf) this.element = event.element(); //alert(this.element.id) if( outsideOf == null ) { //this shouldnt happen, but just incase $(document.body).descendants().invoke ('stopObserving','click',this.outside); return; }; this.element = Event.element(event); if( this.element.descendantOf( $(outsideOf) ) !== true) { outsideOf = null; $(document.body).descendants().invoke ('stopObserving','click',this.outside); document.getElementById(this.start_drop_id).style.display = "none"; //it says this is null }; }; I think I need to use .bind(this) somewhere or maybe bindAsEventListener? I'm not sure. This is my first time writing a prototype class so I am bit lost. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~----------~----~----~----~------~----~------~--~---