Hey,
I'm new to OOP in javascript.
What I have been doing so far to make a "class"/Reusable object is this:

PHP Code:
function Dog(){
    
this.name name;
    
    
this.bark = function(){
        
// some code
    
}

However, recently I have been reading a book on Javascript and it said that the problem with this way of doing it, is that the bark() function will be loaded into memory for each Dog object created this way, while the body of that function is the same for each object. There was an explanation on how it could be done better but I did not understand it fully.

Let's say I want:
- A Person class with a name property and a jump() method.
- An animal class with a isMammal property and move() method.
- A Dog class with a numberOfLegs property and a bark() method which is a subclass of Animal (thus inherits the isMammal property and move() method.
- Each of those classes in its own file.

What would these files look like when I do it the right way?

This book I've been reading is actually pretty good, but at some points it's explanation is not rich enough.

It explains that functions are objects and that objects in javascript are just key-value pairs. It says that each function has a prototype property which points to a blank Object(), but you can make it point to something else? or maybe I misunderstood it. I still don't understand how it really works. Maybe someone can give me a good link or explain me how the whole prototype thing works.

Hope you can help me out, it would really help me to start understanding Javascript better in its entirety. Because most things I can get working now, but I want to know why it works and whether I'm doing it in an efficient way.

Thanks in advance,
Stefan