classes and objects javascript code example
Example 1: javascript classes
class MyClass {
constructor(FirstProperty, SecondProperty, etcetera) {
this.firstProperty = FirstProperty;
this.secondProperty = SecondProperty;
}
method(Parameters) {
}
get getBothValues()
{
return [firstProperty, secondProperty];
}
}
Example 2: how to create object in javascript with class
let myCar1 = new Car("Ford", 2014);
let myCar2 = new Car("Audi", 2019);
Example 3: how to create object in javascript with class
class Car {
constructor(name, year) {
this.name = name;
this.year = year;
}
}