Sorry i put the definition for self in the wrong place Foo = Class.create(); Foo.prototype = { initialize: function() { var self = this; var array = $A([1, 2, 3]); array.each(function (i) { self.hello(); }); },
hello: function() { alert('hello'); } } On 3/17/07, Gareth Evans <[EMAIL PROTECTED]> wrote: > > Just verified- I presume this is by design (so you can access the root > enumerable item per item iterating) but you can solve it like so > > Foo = Class.create(); > Foo.prototype = { > var self = this; > initialize: function() { > var array = $A([1, 2, 3]); > array.each(function (i) { > self.hello(); > }); > }, > > hello: function() { > alert('hello'); > } > } > > > > > On 3/17/07, zven <[EMAIL PROTECTED]> wrote: > > > > > > When I use 'this' keyword in Enumerable.each it always references to > > Enumerable. Is it ok? How to call 'hello' method in loop using > > Enumerable.each? > > > > Foo = Class.create(); > > Foo.prototype = { > > initialize: function() { > > var array = $A([1, 2, 3]); > > array.each(function (i) { > > this.hello(); > > }); > > }, > > > > hello: function() { > > alert('hello'); > > } > > } > > > > > > > > > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---