whoa, sorry guys. the answer was right under my nose in the form of the bind() function... hehe, chalk up another useless post for the new guy. :)
On May 16, 4:45 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > Hi guys. > My problem before dealt with variable values rather than function > access. Here I'm creating an onclick handler, which I want to execute > a sibling function within the object that created it. I've got an > object with several methods, like so: > > object { > addArticle () > removeArticle() > addElement() > > } > > Inside of my addElement I have an onclick assignment like so: > > deletef = function(id) { > // create <img> and <a> elements... > deleteLink.observe('click',function(id){this.removeArticle(id);}); > <--- > return deleteLink; > div.appendChild(deletef(id)); > > I know that the problem is that when I click the link, the function is > now executing in the scope of the <a> element, not in that function. I > tried to assign 'this' to a variable and pass that through, but that > didn't seem to work either. ie. > > addElement (id) { > var scope = this; > > deletef = function(id,scope) { > // create <img> and <a> elements... > deleteLink.observe('click',function(id,scope) > {scope.removeArticle(id);}); <--- > } > > } > > Is there a way for me to preserve the scope from when It was > originally created? --~--~---------~--~----~------------~-------~--~----~ 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-spinoffs@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---