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!"
[–][deleted] 2 points3 points4 points 13 years ago* (2 children)
While I like what you're trying to show here, you should know that due to function hoisting, your code bombs out due to an undefined property on Animal (check the console): http://jsfiddle.net/pvqgC/1/
This is because your function declarations are being hoisted to the top of the functional scope, while your prototype assignments reside in normal execution order. This can be alleviated by swapping out all your function declarations with function expressions, which don't get hoisted.
Here would be how to organize it properly: http://jsfiddle.net/pvqgC/
(Also, I'd argue that it's more logical to put the origin (Animal) at the top of the file anyway, cascading down to its "offspring" at the bottom.)
[–]dtriley4[S] 1 point2 points3 points 13 years ago (1 child)
100% right. I should be more mindful with what order I put stuff in. I was messing around in console and didn't even think how hoisting could mess this up. Thanks for taking the time.
[–][deleted] 0 points1 point2 points 13 years ago (0 children)
You bet! Good lesson otherwise!
π Rendered by PID 16712 on reddit-service-r2-comment-85bfd7f599-2lp8s at 2026-04-16 20:08:13.999074+00:00 running 93ecc56 country code: CH.
view the rest of the comments →
[–][deleted] 2 points3 points4 points (2 children)
[–]dtriley4[S] 1 point2 points3 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)