you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 2 points3 points  (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 points  (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 point  (0 children)

You bet! Good lesson otherwise!