Message from JavaScript discussions

September 2017

— 🌚

— 

Hey guys, i dont understand why to use prototype instead to make methods and fields in the object class

— Prototypes are not instantiated when you use new, meaning it is a static object

— If you assign functions to the class directly with this, then you are copying multiple functions every time you use new

Message permanent page

— Also, assignments done to props on an instance of an object do not overwrite the prototype

— They override the prototype's properties, but they remain untouched

— This also means you can chain prototypes between each other or share them between different classes, all without worrying about it being modified

Message permanent page

— IE, a prototype can have a prototype, and so forth, allowing you to "extend" objects

— That is how the JS basic "class" system works, it's not classes at all but rather chains of objects with properties that override each other from the top-down

Message permanent page

— If you are using ES2015 classes this looks a lot different when you write it out though, as it's some sugar to make it look like normal classes

Message permanent page

— You're insane

— Mad scientist stuff