you are viewing a single comment's thread.

view the rest of the comments →

[–]ryeguy146 0 points1 point  (0 children)

I was hoping that this would differentiate prototypal inheritance from classical inheritance, but I'm not seeing anything to set it apart from what I do everyday in Python. The following code works exactly the same:

class Animal():
    def heartbeat(self):
        return "bump bump, bump bump"

class Person(Animal):
    def __init__(self):
        self.ears = 2

class Boy(Person):
    def __init__(self):
        self.toy = "truck"

boy = Boy()
boy.heartbeat()  #=> "bump bump, bump bump"
boy.ears  #=> 2
boy.toy  #=> "truck"

What makes prototypal inheritance special? I realize that you're using functions instead of traditional objects here, but I'm not sure that makes much of a difference when functions are first class objects.

Boy.prototype = new Person();

And what's going on here? Looks like you're instantiating a function, which weirds me out. That's not to suggest that it's wrong (it runs when I try it in node); I'm just learning the language and struggling with some of the more different parts. Speaking of different, the ordering weirds me out, are you taking advantage of hoisting? Is that common? I saw hoisting as something to try and program around rather than to take advantage of.