In an effort to keep the code clean I'd delegate this functionality to
a dedicated method other than the constructor.
On Aug 4, 2:16 pm, Matt Foster mattfoste...@gmail.com wrote:
If you really wanted to avoid bind you could just use closures within
the initialize method
var Sub4 =
Your observers need to be bound to the object you want the this
keyword tied to.
document.observe('click', this.f.bindAsEventListener(this))
See the bottom of this page:
http://prototypejs.org/api/event/observe
-justin
--~--~-~--~~~---~--~~
You received this
Hi, thanks for the answer.
I want to bind this.f itself, in order to be able to use
Event.stopObserving with it. What is the best way to do it?
Cédric
On Aug 3, 5:32 pm, mr_justin gro...@jperkins.otherinbox.com wrote:
Your observers need to be bound to the object you want the this
keyword
Hi,
But it's really inelegant. How am I supposed to handle this?
Pretty much like that, except I haven't reassigned the property like
that. It *should* be fine, you'll create an own property 'f' on the
instance (rather than an inherited one from the prototype) that's
bound. But it bothers me
Thanks. I'll use #bind instead of #bindAsEventListener from now on.
Regarding the binding inelegancy, I'm a bit disappointed, but at least
it's a good working solution to the problem.
I guess Class#addMethods won't be of any help here?
--~--~-~--~~~---~--~~
You
Regardless of the JS framework. A closure is necessary for attaching
class methods to a particular instance and preserve the instance
reference via the this keyword.
http://www.javascriptkit.com/javatutors/closures.shtml
I thought Function.bind was pretty clean myself, but I guess you've
got
Oops, sorry for the weird formatting...
On Mon, Aug 3, 2009 at 6:38 PM, Ryan Gahl ryan.g...@gmail.com wrote:
Let me suggest the module pattern - which not inconsequently also enables
true private fields and methods (just because it seems you're looking for
alternative patterns). Also, since