javascript constructors Flashcards
EXAMPLE:
function Car(make, model, year) {
this.make = make;
this.model = model;
this.year = year;
}
const car1 = new Car(‘Eagle’, ‘Talon TSi’, 1993);
console.log(car1.make);
// Expected output: “Eagle”
SYNTAX:
new constructor
new constructor()
new constructor(arg1)
new constructor(arg1, arg2)
new constructor(arg1, arg2, /* …, */ argN)
ANOTHRE EXAMPLE:
function Car(make, model, year) {
this.make = make;
this.model = model;
this.year = year;
}
create object (for the example):
const myCar = new Car(“Eagle”, “Talon TSi”, 1993);
What does the new operator do?
What property of JavaScript functions can store shared behavior for instances created with new?
their prototype
What does the instanceof operator do?
checks if a constructor function matches the one specified