oh forgot to send the code showing an example on how it works now:

http://jsfiddle.net/cVbSB/

--
Fábio Miranda Costa
Solucione Sistemas
Engenheiro de interfaces


2010/4/16 Fábio M. Costa <[email protected]>

> Interesting. So currently the mixin's methods won't overwrite the methods
> you have on your class. You should avoid having a method with the same name
> of your mixins.
>
> The behavior your explaining makes sense to me, so i'll discuss with other
> devs about it.
>
> Thanks.
>
>
>
> --
> Fábio Miranda Costa
> Solucione Sistemas
> Engenheiro de interfaces
>
>
> On Fri, Apr 16, 2010 at 4:21 PM, Bogdan Gusiev <[email protected]> wrote:
>
>> Sorry, I am total JS noob.
>> I just can tell you does it work in Ruby:
>> Mixins are not multiple inheritance. They are appending to the Class
>> tree between the current class and it's parent class.
>>
>> Let's say that Person extends Model with mixins Cached and
>> ActivitySpawner:
>>
>> Model has method #save:
>> save: function() { // query DB }
>>
>> Cached has method #save:
>> save: function() { this.parent(); Cache.persist(this)}
>>
>> ActivitySpawner has also method #save:
>> save: function() {this.parent(); new Activity(this, "new object
>> created");}
>>
>> And User also have it:
>> save: function() {this.parent(); new ActivationEmail(this.email);}
>>
>> In this case
>> Class  | save method parent
>> Model | none
>> Cached | Model#save
>> ActivitySpawner | Cached#save
>> Person | ActivitySpawner#save
>>
>> Sure, the order of mixins make sense. But in fact in this example I
>> don't care about the order - I just want all 'on Save' things to be
>> done.
>>
>>
>>
>>
>>
>> On Apr 16, 9:59 pm, Fábio M. Costa <[email protected]> wrote:
>> > Yeah you can just access the parent function from the Extended Class.
>> Thats
>> > the intended behavior.
>> > I mean who's the parent of who if you mix 2 classes that have the same
>> > method names?
>> > I'm confused now.
>> >
>> > --
>> > Fábio Miranda Costa
>> > Solucione Sistemas
>> > Engenheiro de interfaces
>> >
>> >
>> >
>> > On Fri, Apr 16, 2010 at 3:56 PM, Bogdan Gusiev <[email protected]>
>> wrote:
>> >
>> > > "if (this.parent)" doesn't work for me. It is always defined.
>> >
>> > > I will try to describe the whole situation:
>> >
>> > > I have two mixins for the Widget class:
>> > > Animated is responding for animation.
>> > > Stateful is doing widget state control.
>> >
>> > > Both of them have show() and hide() methods.
>> > > But these mixins are independent from each other and I want to be able
>> > > to use them one by one and together.
>> >
>> > > In addition, it's sad that 'parent' is inaccessible in class mixed up
>> > > with 'Implements'.
>> >
>> > > On Apr 16, 8:30 pm, Fábio M. Costa <[email protected]> wrote:
>> > > > Could you explain why you need this?
>> > > > It makes little sense to me.
>> > > > Anyway you can do:
>> >
>> > > > if (this.parent) this.parent();
>> >
>> > > > --
>> > > > Fábio Miranda Costa
>> > > > Solucione Sistemas
>> > > > Engenheiro de interfaces
>> >
>> > > > On Fri, Apr 16, 2010 at 1:07 PM, Bogdan Gusiev <[email protected]>
>> > > wrote:
>> > > > > Good morning JS geeks,
>> >
>> > > > > Can somebody advice is there a way to check if class method exists
>> in
>> > > > > Extended class?
>> >
>> > > > > Like:
>> >
>> > > > > new Class({
>> >
>> > > > > Extends: UnknownClass,
>> >
>> > > > > show: function() {
>> > > > >  if (this.hasParent()) {
>> > > > >    this.parent();
>> > > > >  }
>> > > > >  this.doSomethingElse();
>> > > > > }
>> >
>> > > > > });
>> >
>> > > > > --
>> > > > > Subscription settings:
>> > > > >http://groups.google.com/group/mootools-users/subscribe?hl=en
>>
>
>

Reply via email to