+ 3
Please javascript is becoming a bit confusing.
What is the difference between these two object types Object ={name:'Sam', age:15, job:"coding"} function object (name, age,job){ this. name = name this. age=age this. job=job } var x = new object("Sam",15,"coding") The confusion is that in python, we would have called the first a dictionary and that would have been better, but what confuses me is the one to use and even when to use it 😩😩
4 odpowiedzi
+ 10
The second example is an object created from a constructor function. The advantage becomes evident when you want to create many similar objects. It will be cumbersome to create them all by hand.
+ 5
the 1st one is hard coded ,
means you give their values ,
the second one is dynamic and we call that func a constructor function , .
its like a machine that create objects.
(this keyword in js is like self in py)
and the way you can call it is by using the new keyword instead of calling it like a regular function ..
and i recommend google it , its little bit hard to understand on the beginning
+ 3
Ore thanks a whole lot 😁😁
+ 2
More explanation
https://code.sololearn.com/W45dEI0uqD2u/