Quantcast

accessing a static member of a mixin within the mixin

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

accessing a static member of a mixin within the mixin

Dietrich Streifert
Hi all,

if I have a mixin like this:

qx.Mixin.define("myapp.MMixin",
{
  statics : {
    myhash: {}
  },

  members: {
    mymethod : function() {
       this.self(arguments).myhash.foo = 'bar'; // this does not work !!!!

       this.constructor.myhash.foo = 'bar'; // this does not work !!!!
    }
  }
});

How do I access the static member myhash? The code above does not work!

The mixin is of course used via include in another class.

Any help would be great!

Regards
Dietrich


------------------------------------------------------------------------------

_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: accessing a static member of a mixin within the mixin

Derrell Lipman
Static members are accessed in exactly the same way regardless of whether they're in a mixin or not. In this case, you'd access "myapp.MMixin.myhash" because myhash is a static of the mixin itself.

Derrell


On Wed, Dec 23, 2015 at 9:52 AM Dietrich Streifert <[hidden email]> wrote:
Hi all,

if I have a mixin like this:

qx.Mixin.define("myapp.MMixin",
{
  statics : {
    myhash: {}
  },

  members: {
    mymethod : function() {
       this.self(arguments).myhash.foo = 'bar'; // this does not work !!!!

       this.constructor.myhash.foo = 'bar'; // this does not work !!!!
    }
  }
});

How do I access the static member myhash? The code above does not work!

The mixin is of course used via include in another class.

Any help would be great!

Regards
Dietrich

------------------------------------------------------------------------------
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

------------------------------------------------------------------------------

_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: accessing a static member of a mixin within the mixin

Dietrich Streifert
Hi Derrell,

but I want myhash to be specific to the class where the mixin is mixed in.

So if I mixin to myapp.A and also to myapp.B the myhash static should be different for each class A and B.

Am 23.12.2015 um 15:58 schrieb Derrell Lipman:
Static members are accessed in exactly the same way regardless of whether they're in a mixin or not. In this case, you'd access "myapp.MMixin.myhash" because myhash is a static of the mixin itself.

Derrell


On Wed, Dec 23, 2015 at 9:52 AM Dietrich Streifert <[hidden email]> wrote:
Hi all,

if I have a mixin like this:

qx.Mixin.define("myapp.MMixin",
{
  statics : {
    myhash: {}
  },

  members: {
    mymethod : function() {
       this.self(arguments).myhash.foo = 'bar'; // this does not work !!!!

       this.constructor.myhash.foo = 'bar'; // this does not work !!!!
    }
  }
});

How do I access the static member myhash? The code above does not work!

The mixin is of course used via include in another class.

Any help would be great!

Regards
Dietrich


------------------------------------------------------------------------------

_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: accessing a static member of a mixin within the mixin

Derrell Lipman
I don't think you can do that. The static is part of the mixin, it's not per whatever it's mixed in to. Maybe you want to create a singleton class to do that?

Derrell


On Wed, Dec 23, 2015 at 10:03 AM Dietrich Streifert <[hidden email]> wrote:
Hi Derrell,

but I want myhash to be specific to the class where the mixin is mixed in.

So if I mixin to myapp.A and also to myapp.B the myhash static should be different for each class A and B.


Am 23.12.2015 um 15:58 schrieb Derrell Lipman:
Static members are accessed in exactly the same way regardless of whether they're in a mixin or not. In this case, you'd access "myapp.MMixin.myhash" because myhash is a static of the mixin itself.

Derrell


On Wed, Dec 23, 2015 at 9:52 AM Dietrich Streifert <[hidden email]> wrote:
Hi all,

if I have a mixin like this:

qx.Mixin.define("myapp.MMixin",
{
  statics : {
    myhash: {}
  },

  members: {
    mymethod : function() {
       this.self(arguments).myhash.foo = 'bar'; // this does not work !!!!

       this.constructor.myhash.foo = 'bar'; // this does not work !!!!
    }
  }
});

How do I access the static member myhash? The code above does not work!

The mixin is of course used via include in another class.

Any help would be great!

Regards
Dietrich

------------------------------------------------------------------------------
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

------------------------------------------------------------------------------

_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: accessing a static member of a mixin within the mixin

Derrell Lipman
No, sorry, singleton is the opposite of what you want. Just some other regular class.

Derrell


On Wed, Dec 23, 2015 at 10:07 AM Derrell Lipman <[hidden email]> wrote:
I don't think you can do that. The static is part of the mixin, it's not per whatever it's mixed in to. Maybe you want to create a singleton class to do that?

Derrell


On Wed, Dec 23, 2015 at 10:03 AM Dietrich Streifert <[hidden email]> wrote:
Hi Derrell,

but I want myhash to be specific to the class where the mixin is mixed in.

So if I mixin to myapp.A and also to myapp.B the myhash static should be different for each class A and B.


Am 23.12.2015 um 15:58 schrieb Derrell Lipman:
Static members are accessed in exactly the same way regardless of whether they're in a mixin or not. In this case, you'd access "myapp.MMixin.myhash" because myhash is a static of the mixin itself.

Derrell


On Wed, Dec 23, 2015 at 9:52 AM Dietrich Streifert <[hidden email]> wrote:
Hi all,

if I have a mixin like this:

qx.Mixin.define("myapp.MMixin",
{
  statics : {
    myhash: {}
  },

  members: {
    mymethod : function() {
       this.self(arguments).myhash.foo = 'bar'; // this does not work !!!!

       this.constructor.myhash.foo = 'bar'; // this does not work !!!!
    }
  }
});

How do I access the static member myhash? The code above does not work!

The mixin is of course used via include in another class.

Any help would be great!

Regards
Dietrich

------------------------------------------------------------------------------
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

------------------------------------------------------------------------------

_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: accessing a static member of a mixin within the mixin

Dietrich Streifert
Ah, OK. Thank you Derrell.

Then I have to use something else to make this work.

I need a mechanism which initializes some class specific static hash within the mixin, depending on the class the mixin is included to.
After initialization of the hash, which is finished after the first instantiation of the class, the hash should be used by any subsequent instance.
But the hash has to be specific to that class.

One possibility would be to have a hash of hashes within the mixin, which is specific to the class where the mixin is included to.
But this assumes that the mixin is capable of retrieving the class to which it is mixed in.



Am 23.12.2015 um 16:08 schrieb Derrell Lipman:
No, sorry, singleton is the opposite of what you want. Just some other regular class.

Derrell


On Wed, Dec 23, 2015 at 10:07 AM Derrell Lipman <[hidden email]> wrote:
I don't think you can do that. The static is part of the mixin, it's not per whatever it's mixed in to. Maybe you want to create a singleton class to do that?

Derrell


On Wed, Dec 23, 2015 at 10:03 AM Dietrich Streifert <[hidden email]> wrote:
Hi Derrell,

but I want myhash to be specific to the class where the mixin is mixed in.

So if I mixin to myapp.A and also to myapp.B the myhash static should be different for each class A and B.


Am 23.12.2015 um 15:58 schrieb Derrell Lipman:
Static members are accessed in exactly the same way regardless of whether they're in a mixin or not. In this case, you'd access "myapp.MMixin.myhash" because myhash is a static of the mixin itself.

Derrell


On Wed, Dec 23, 2015 at 9:52 AM Dietrich Streifert <[hidden email]> wrote:
Hi all,

if I have a mixin like this:

qx.Mixin.define("myapp.MMixin",
{
  statics : {
    myhash: {}
  },

  members: {
    mymethod : function() {
       this.self(arguments).myhash.foo = 'bar'; // this does not work !!!!

       this.constructor.myhash.foo = 'bar'; // this does not work !!!!
    }
  }
});

How do I access the static member myhash? The code above does not work!

The mixin is of course used via include in another class.

Any help would be great!

Regards
Dietrich



------------------------------------------------------------------------------

_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: accessing a static member of a mixin within the mixin

Derrell Lipman
Looking at the source code for qx.Class, the mixin constructor is called as follows:

              mixins[i].$$constructor.apply(this,arguments);

This looks to me like 'this' in the constructor will be the instance of the class doing the mixing in (include), not the mixin itself. If that's the case, you can do:

    hash = qx.core.ObjectRegistry.toHashCode(this);

to get the hash of the including, not included, class instance. 

You should also be able to get the class name of 'this' with:

    this.toString().replace(/\[.*/, "")

Hope that helps.

Derrell



On Wed, Dec 23, 2015 at 10:35 AM Dietrich Streifert <[hidden email]> wrote:
Ah, OK. Thank you Derrell.

Then I have to use something else to make this work.

I need a mechanism which initializes some class specific static hash within the mixin, depending on the class the mixin is included to.
After initialization of the hash, which is finished after the first instantiation of the class, the hash should be used by any subsequent instance.
But the hash has to be specific to that class.

One possibility would be to have a hash of hashes within the mixin, which is specific to the class where the mixin is included to.
But this assumes that the mixin is capable of retrieving the class to which it is mixed in.




Am 23.12.2015 um 16:08 schrieb Derrell Lipman:
No, sorry, singleton is the opposite of what you want. Just some other regular class.

Derrell


On Wed, Dec 23, 2015 at 10:07 AM Derrell Lipman <[hidden email]> wrote:
I don't think you can do that. The static is part of the mixin, it's not per whatever it's mixed in to. Maybe you want to create a singleton class to do that?

Derrell


On Wed, Dec 23, 2015 at 10:03 AM Dietrich Streifert <[hidden email]> wrote:
Hi Derrell,

but I want myhash to be specific to the class where the mixin is mixed in.

So if I mixin to myapp.A and also to myapp.B the myhash static should be different for each class A and B.


Am 23.12.2015 um 15:58 schrieb Derrell Lipman:
Static members are accessed in exactly the same way regardless of whether they're in a mixin or not. In this case, you'd access "myapp.MMixin.myhash" because myhash is a static of the mixin itself.

Derrell


On Wed, Dec 23, 2015 at 9:52 AM Dietrich Streifert <[hidden email]> wrote:
Hi all,

if I have a mixin like this:

qx.Mixin.define("myapp.MMixin",
{
  statics : {
    myhash: {}
  },

  members: {
    mymethod : function() {
       this.self(arguments).myhash.foo = 'bar'; // this does not work !!!!

       this.constructor.myhash.foo = 'bar'; // this does not work !!!!
    }
  }
});

How do I access the static member myhash? The code above does not work!

The mixin is of course used via include in another class.

Any help would be great!

Regards
Dietrich


------------------------------------------------------------------------------
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

------------------------------------------------------------------------------

_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: accessing a static member of a mixin within the mixin

Dietrich Streifert
I'm currently simply adding the hash on first init to

this.constructor.myhash = {};

which is dirty but works.

I think I'll go with your proposal using the constructor of the mixin.

Thank you for your help.

Regards
Dietrich

Am 23.12.2015 um 16:54 schrieb Derrell Lipman:

> Looking at the source code for qx.Class, the mixin constructor is
> called as follows:
>
> mixins[i].$$constructor.apply(this,arguments);
>
> This looks to me like 'this' in the constructor will be the instance
> of the class doing the mixing in (include), not the mixin itself. If
> that's the case, you can do:
>
>     hash = qx.core.ObjectRegistry.toHashCode(this);
>
> to get the hash of the including, not included, class instance.
>
> You should also be able to get the class name of 'this' with:
>
>     this.toString().replace(/\[.*/, "")
>
> Hope that helps.
>
> Derrell
>
>
>


------------------------------------------------------------------------------
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Loading...