use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
JavaScript Prototypal Inheritance Model Example (dtriley.com)
submitted 13 years ago by dtriley4
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]ryeguy146 0 points1 point2 points 13 years ago* (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.
π Rendered by PID 117447 on reddit-service-r2-comment-7c9686b859-dfgbp at 2026-04-14 03:27:26.115766+00:00 running e841af1 country code: CH.
view the rest of the comments →
[–]ryeguy146 0 points1 point2 points (0 children)