PDA

View Full Version : Howto access loading Class out of Mixins Function (this; parent; ...?)



Malte123
29 Jan 2014, 3:45 PM
Maybe I am only confused and need simple clearing?...:

If I want to call a Mixins Function I know:


this.mixins.mixinname.mixedinFunction();

but if I am within mixedinFunction, how to access the old this ?

"parent" or "this" is not the right way I think.

Malte123
29 Jan 2014, 3:47 PM
if this is right ... I have done a mistake and got confised this way.

Malte123
29 Jan 2014, 5:12 PM
I found an early discussion in forum:
http://www.sencha.com/forum/showthread.php?252009-get-reference-to-parent-object-from-within-a-mixin

but for me it isn't clear cut - mitchellsimoens (http://www.sencha.com/forum/member.php?22216-mitchellsimoens) talk about:

So the mixin can reference the parent class via the scope and the parent class can reference the mixin either by the this.mixins object or the things the mixins place on the parent class.

what does the line


this.mixins.mymixin.foo.call(this);

do ?

Is the call(this) on mixed in method what he talk about saying "scope" ?

If I try this for my needs on a predefined string param (not a function) it causes in a value "undefined".

So based on the Example in the old thread - how has to look a call of a param instead - for example ?!

If I do out of mixins.mymixin.foo a call to Parent Classes function called this.parentClassTestFunction (because in my opinion all methods are in one scope) I get


TypeError: 'undefined' is not a function (evaluating 'this.parentClassTestFunction()')

In my way to expect clear to only logical way to expect how it should work:

Within mixins.mymixin.foo:

console.log(this.parentparam) // should pull out the value is stored in mixin loading classes param parentparam


Same for function-calls to mixin loading Class within mixins function.

Please do a clear clarification to this FAQ (I think) :-)

If he mean by saying "reference the parent class via the scope" you have to send the Scope to this.mixins.mymixin.foo(this) it would nullify the sense of mixins for me. It blows up memory needs only to be able working with.
If he mean this - please discuss how to do this a better way :-)

Malte123
30 Jan 2014, 9:01 PM
motivated to bring Question up to first page :D ... once more asking:

Is there not a good Answer to this good Question ?

Thanks for Thinking about :)

mitchellsimoens
3 Feb 2014, 9:09 AM
this.mixins.mymixin.foo.call(this);

What this does is gets the mixin class by name (mymixin in this case) and simple calls the foo method with scope of the parent class. This is usually used when the parent class has a same method name as the mixin and you need to call the mixin method.

For example. Ext.util.Observable is a mixin in Ext.AbstractComponent. Each class has a constructor method but Ext.AbstractComponent needs to call the constructor method of Ext.util.Observable so Ext.AbstractComponent does:


me.mixins.observable.constructor.call(me);

The me variable is a local variable assigned to this and this code is in the initComponent method of Ext.AbstactComponent.

If you are within a method of the mixin, the scope should be of the parent class. A mixin's methods and properties are set onto the parent class unless the parent class has a member with the same name (the mixin will not overwrite the parent class)