I am used to the concept of classes and objects like in java
or c++
. In javascript the way objects are coded seems strange to me
var a = {property1:1, property2:100};
This looks like a map in python
. I already understand that this can achieve most of what I expect of a object since I can store functions into variables. However I also saw that you can use
class testclass {
constructor(property1, property2) {
this.property1 = property1;
this.property2 = property2;
}
}
var a = new testclass(1,100);
to create objects. Now the question which arises is what is the difference to the following?
function testclass(property1, property2) {
this.property1 = property1
this.property2 = property2
}
var a = new testclass(1,100);
In my understanding a object is a instance of a class but in the first example it is more a map which is maybe a instance of a class but in this kind of view every object is a instance of the same class...
I hope somebody can enlighten me.