You can use the bind method.

  this.formElements.each(function (el, index) { ... }.bind(this));

- Jon L.

On Feb 12, 2:05 pm, kojilab <[EMAIL PROTECTED]> wrote:
> Hi
>
> I have an object with a method I call run that iterates over some form
> elements.
> I want to be able to execute a method of that object on each element.
> But when I use this in the function within the each() statement,
> obviously the this doesn't correspond to the object instance.
> Thanks for your help
>
> Code snippet:
> MyObject=Class.create();
>
> MyObject.prototype = {
>   run: function(){
>     this.formElements.each(function(el, index){
>       this.doSomething(el);
>     });
>   },
>  doSomething:function(){
>   return;
>  }
>
> }
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype: Core" group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to