Alternate title: "Why do so many popular JavaScript libraries use pseudoclassical inheritance as opposed to functional inheritance (factory functions)?"
JavaScript: The Good Parts advises the use of factory functions so that you get true privacy of methods and properties. This makes sense, so I'm wondering why so many modern JS libraries still use psuedoclassical inheritance (using the new keyword). Is there some technical advantage of going this route as opposed to factory functions? If not, is it just a stylistic choice?
EDIT: This is not an opinion-based post. I'm not asking which is better, I'm asking what technical advantages pseudoclassical inheritance has over functional to gain an understanding why someone would choose that style.
EDIT 2: A couple advantages of pseudoclassical I can see:
- When you
console.logan instance of a prototype, it shows you the name of the object it was instanced from. - On a related note, you can use
instanceofto see if an instance came from a particular object, which is not possible with factory functions.