Objects and instances in python & javascript?

I have studied python (a thin getting started manual) and have been reading javascript recently.
confused ~
about the classes, objects, and prototypes of the two, so I understood it this way, and I don"t know whether it is correct or not.
I hope you can solve the problem.

Jan.23,2022

your JavaScript prototype instance is actually one step short: the prototype "constructor" instance.
example:
function Dog (name) {/ / constructor
this.name = name;
}
Dog.prototype = {species:' Canine'}; / / prototype
var mydog = new Dog ('Kiki'); / / instance

if you really want to make an analogy, the class of Python should the constructor of js, because the prototype cannot new an instance, and the prototype is essentially an object.

to take it a step further, in fact, there were no classes in the design of the language js, and even if es6 provided the syntax of class, it was just a syntax candy. There is no class talk in js design, but in order to meet the requirements of object-oriented programming, new, can new an instance. However, the method of new (we also call it a constructor) is essentially a function, and the function has a function scope, which means that data can not be shared between different instances. That is, there are often static class variables and member variables in our class. But the existence of the function scope allows him to only create member variables. That's why the prototype prototype object appears, enabling it to create static class variables. All functions have the property of prototype object
, that is, Dog.prototype = {}
, so you need to know that prototype object is not equal to class

.
Menu