Thanks for these ideas.

I'm still not sure if I will use these sub objects, but here is the
solution I came for : http://jsfiddle.net/nBn2t/2/

In this case this.parent refers to the class' this and seems quite
coherent...

Regards, Olivier.



On 27 mar, 19:11, Dimitar Christoff <[email protected]> wrote:
> On 27/03/2012 17:46, Matthew Hazlett wrote:
>
> > In the init add:
> > root = this;
>
> > then in the child object change:
> > this.b() to root.b();
>
> >http://jsfiddle.net/hazlema/nBn2t/
>
> root becomes a single global variable, pointing to THAT instance. any
> other instances will overwrite it and it all sounds like an
> anti-pattern. even if you somehow use a closure and protect this 'leak'
> so it's per-instance, it's still not a good idea.
>
> Child is a new object and scope _should_ be different - it will be the
> actual Child object.
>
> you can this.Child.a.call(this) to change scope and run it in the next
> context of the instance.
>
> you can also change Child to be a function that returns an object or
> self-memoizes on first call to turn into an object but with the correct
> bindings since the function will correctly reference the instance on the
> first run and can then bind the object methods.
>
> but you really ought to look at separating the two or using other
> classes / instances.
>
> Good luck.
> --
> Dimitar Christoff
>
> "JavaScript is to JAVA what hamster is to ham"http://fragged.org/| @D_mitar 
> |https://github.com/DimitarChristoff

Reply via email to