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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---
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
<Alexander.Uvarov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---
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 <agrath-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
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
<Alexander.Uvarov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---
Thx, Gareth. I already found solution. Other possible solution is:
with(this) { ... }
On Mar 17, 8:58 am, "Gareth Evans"
<agr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> 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
<agr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---
For my, and other group members benefit, could you please paste your final solution? I do not know what you mean by with(this) so I want to see in case it is a better solution for the problem if I have it in the future. Gareth On 3/17/07, zven <Alexander.Uvarov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > Thx, Gareth. I already found solution. Other possible solution is: > with(this) { ... } > > On Mar 17, 8:58 am, "Gareth Evans" <agr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > 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 <agr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Foo = Class.create();
Foo.prototype = {
initialize: function() {
var array = $A([1, 2, 3]);
with(this) {
array.each(function (i) {
hello();
});
}
},
hello: function() {
alert(''hello'');
}
On Mar 17, 9:20 am, "Gareth Evans"
<agr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> For my, and other group members benefit, could you please paste your final
> solution?
> I do not know what you mean by with(this) so I want to see in case it is a
> better solution for the problem if I have it in the future.
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
<pre wrap="">Foo = Class.create();
Foo.prototype = {
initialize: function() {
var array = $A([1, 2, 3]);
array.each(function (i) {
this.hello();
}.bind(this));
},
hello: function() {
alert(''hello'');
}
};
</pre>
Gareth Evans wrote:
<blockquote
cite="mid:46944cba0703162120v112218faqf4f0b70eb074bde2-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org"
type="cite">
<div>For my, and other group members benefit, could you please paste
your final solution?</div>
<div>I do not know what you mean by with(this) so I want to see in
case it is a better solution for the problem if I have it in the
future.</div>
<div> </div>
<div>Gareth<br>
<br>
</div>
<div><span class="gmail_quote">On 3/17/07, <b
class="gmail_sendername">zven</b> <<a
moz-do-not-send="true"
href="mailto:Alexander.Uvarov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org">Alexander.Uvarov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org</a>>
wrote:</span>
<blockquote class="gmail_quote"
style="border-left: 1px solid rgb(204, 204, 204); margin: 0px 0px 0px
0.8ex; padding-left: 1ex;"><br>
Thx, Gareth. I already found solution. Other possible solution is:<br>
with(this) { ... }<br>
<br>
On Mar 17, 8:58 am, "Gareth Evans" <
<a moz-do-not-send="true"
href="mailto:agr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org">agr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org</a>>
wrote:<br>
> Sorry i put the definition for self in the wrong place<br>
><br>
> Foo = Class.create();<br>
> Foo.prototype = {<br>
> initialize: function() {
<br>
> var
self = this;<br>
> var
array = $A([1, 2, 3]);<br>
> array.each(function
(i) {<br>
> self.hello();<br>
> });<br>
> },<br>
><br>
> hello: function() {<br>
> alert(''hello'');<br>
> }<br>
><br>
> }<br>
><br>
> On 3/17/07, Gareth Evans <<a moz-do-not-send="true"
href="mailto:agr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org">agr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org</a>>
wrote:<br>
><br>
<br>
<br>
<br>
<br>
</blockquote>
</div>
</blockquote>
<br>
--~--~---------~--~----~------------~-------~--~----~<br>
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Spinoffs" group. <br> To post to this
group, send email to
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <br> To
unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
<br> For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en <br>
-~----------~----~----~----~------~----~------~--~---<br>
</body>
</html>
<br>
Thanks Colin, I knew there was a bind solution as I hear people talking about it but I hadn''t specifically looked for a solution. Gareth On 3/17/07, Colin Mollenhour <eliteii92g-NPSFNn/7+NYVo650/ln6uw@public.gmane.org> wrote:> > Foo = Class.create();Foo.prototype = { > initialize: function() { > var array = $A([1, 2, 3]); > array.each(function (i) { > this.hello(); > }.bind(this)); > }, > hello: function() { > alert(''hello''); > } > }; > > Gareth Evans wrote: > > For my, and other group members benefit, could you please paste your final > solution? > I do not know what you mean by with(this) so I want to see in case it is a > better solution for the problem if I have it in the future. > > Gareth > > > On 3/17/07, zven <Alexander.Uvarov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > Thx, Gareth. I already found solution. Other possible solution is: > > with(this) { ... } > > > > On Mar 17, 8:58 am, "Gareth Evans" < agr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > 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 <agr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---