+ 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 😩😩

31st Oct 2020, 9:53 AM
Pythøñ Cúltîst⚔️🔥🇳🇬
Pythøñ  Cúltîst⚔️🔥🇳🇬 - avatar
4 Réponses
+ 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.
31st Oct 2020, 9:59 AM
Ore
Ore - avatar
+ 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
31st Oct 2020, 10:06 AM
Med Amine Fh
Med Amine Fh - avatar
+ 3
Ore thanks a whole lot 😁😁
31st Oct 2020, 10:01 AM
Pythøñ Cúltîst⚔️🔥🇳🇬
Pythøñ  Cúltîst⚔️🔥🇳🇬 - avatar
31st Oct 2020, 10:21 AM
Ore
Ore - avatar