1 decade ago by Matthias
Hey everyone,
I'm wondering if it's possible to inherit from multiple classes when defining a new entity. This didn't work:
EntityDoor = EntityHasHandle.extend( {
...
});
EntityDoor = EntityPushable.extend({
...
});
I know that it's possible to have chained inheritance, that is, an object A can inherit from an object B that inherits from object C, and so on. But here I have a situation where the classes B and C that I want to inherit from do not stand in an inheritance relation by themselves.
I've already read the class documentation at
http://impactjs.com/documentation/class-reference/class
The only thing I thought about was that it may be possible to use a combination of inheritance and injection. I.e. one would inherit from class B and then inject the contents of class C. But that doesn't seem possible, as inject() seems to accept only text and no class objects.
Any ideas? In the worst-case I'd just have to create a mega class, i.e., let B inherit from C - that wouldn't be very elegant though because it doesn't make much sense but I guess it would work.
I'm wondering if it's possible to inherit from multiple classes when defining a new entity. This didn't work:
EntityDoor = EntityHasHandle.extend( {
...
});
EntityDoor = EntityPushable.extend({
...
});
I know that it's possible to have chained inheritance, that is, an object A can inherit from an object B that inherits from object C, and so on. But here I have a situation where the classes B and C that I want to inherit from do not stand in an inheritance relation by themselves.
I've already read the class documentation at
http://impactjs.com/documentation/class-reference/class
The only thing I thought about was that it may be possible to use a combination of inheritance and injection. I.e. one would inherit from class B and then inject the contents of class C. But that doesn't seem possible, as inject() seems to accept only text and no class objects.
Any ideas? In the worst-case I'd just have to create a mega class, i.e., let B inherit from C - that wouldn't be very elegant though because it doesn't make much sense but I guess it would work.