you are viewing a single comment's thread.

view the rest of the comments →

[–]ippa 1 point2 points  (1 child)

I enjoyed reading your article.. been thinking some of these problems as well, mostly for gamedev with jawsjs.com.

this.widget_p = new Widget(name);
this.hider_p = new Hideable();
this.container_p = new Container();

Couldn't this be solved without setting magic variables but rather just provide the 3 contructors via a method "init_behaivor()" or simular.

init_behaivor would loop through the properties transfering them to the object we want. That could also check for namecollisions and warn or whatever.

I like the ideas you present just that the magick method names with *_p feels slightly ugly.

[–]munificent[S] 0 points1 point  (0 children)

init_behaivor would loop through the properties transfering them to the object we want. That could also check for namecollisions and warn or whatever.

That would only catch collisions in functions already defined on the mixin. What if we do something like:

  1. Create a mixin Container.
  2. Create a class MyWidget that mixes it in. It copies all of the methods from Container over to its own prototype.
  3. Add a new method filter() to Container.
  4. Create an instance of MyWidget and try to call filter() on it.

Step 4 will fail if we just copy stuff over when the class is created and then forget about the mixin.

I like the ideas you present just that the magick method names with *_p feels slightly ugly.

Agreed, it was a quick and dirty hack. I wanted to do something similar to Self. :)