Timeline for How prototypal inheritance is practically different from classical inheritance?
Current License: CC BY-SA 3.0
5 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Aug 8, 2013 at 11:41 | comment | added | Joeri Sebrechts | @mVChr: You're still inheriting behavior and not state in that case, which points to classical inheritance, but it does point to an issue with my definition of "inherits the behavior the moment the object is instantiated". I'm not quite sure how to correct the definition. | |
Aug 8, 2013 at 8:34 | comment | added | mVChr |
So Python doesn't have classical inheritance? If I have class C(object): def m(self, x): return x*2 and then instance = C() then when I run instance.m(3) I get 6 . But if I then change C so C.m = lambda s, x: x*x and I run instance.m(3) I now get 9 . The same goes if I make a class D(C) and change a method on C then any instances of D receive the changed method as well. Am I misunderstanding or does this mean that Python does not have Classical inheritance according to your definition?
|
|
May 21, 2012 at 7:16 | comment | added | Joeri Sebrechts | It occurs to me that in javascript there really is no concept of behavior separate from state. Aside from the constructor function all behavior can be assigned/modified post-object-creation just like any other state. | |
Aug 8, 2011 at 19:53 | comment | added | Sean McMillan | In practice, if you're inheriting state, you're setting yourself up for a world of hurt. Inherited state will become shared if it lives on another object. | |
Aug 8, 2011 at 15:54 | history | answered | Joeri Sebrechts | CC BY-SA 3.0 |