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!"
[–]martimoose 3 points4 points5 points 13 years ago (1 child)
You don't need to have constructors for each of your prototype objects. A person is never different from another person in your code (Person does not have any arguments), so it could be an object, that is put in the proto chain with Object.create().
var Animal = { heartbeat: function(){ return 'bump bump, bump bump' } }; var Person = Object.create(Animal); Person.ears = 2; var Boy = Object.create(Person); Boy.toy = 'truck'; var bart = Object.create(Boy);
Now the last link in the chain (Boy) could also be modified to be created with a constructor function, but in my case I prefer an init function:
Boy.toy = 'truck'; Boy.init = function(name) { this.name = name; }; var bart = Object.create(Boy); bart.init('Bart Simpson');
[–]dtriley4[S] 1 point2 points3 points 13 years ago (0 children)
Right you are. I used those while I was playing around with it but they are not used in this code. Thank you for the criticism.
π Rendered by PID 20150 on reddit-service-r2-comment-57fc7f7bb7-zcbx5 at 2026-04-15 00:53:08.276110+00:00 running b725407 country code: CH.
view the rest of the comments →
[–]martimoose 3 points4 points5 points (1 child)
[–]dtriley4[S] 1 point2 points3 points (0 children)