+ 1
Js intermediate help
I am having trouble with the object module in js intermediate. I can not understand the lessons: creating objects, object initialization please help
2 odpowiedzi
+ 2
You can create an object using an object initializer.
const obj = {
property1: value1, // property name may be an identifier
2: value2, // or a number
"property n": value3, // or a string
};
Alternatively, you can first create a constructor function
function Car(make, model, year) {
this.make = make;
this.model = model;
this.year = year;
}
and then instantiate an object by invoking that function with the new operator
const myCar = new Car("Eagle", "Talon TSi", 1993);
+ 1
Thanks