1var MyConstructor = function(p1, p2, p3){
2 this.p1 = p1;
3 this.p2 = p2;
4 this.p3 = p3;
5};
1class Person {
2 constructor(name) {
3 this.name = name;
4 }
5 introduce() {
6 console.log(`Hello, my name is ${this.name}`);
7 }
8}
1function Car(make, model, year) {
2 this.make = make;
3 this.model = model;
4 this.year = year;
5}
6
7var car1 = new Car('Eagle', 'Talon TSi', 1993);
8
9console.log(car1.make);
10// expected output: "Eagle"
1function Person(first, last, age, eye) {
2 this.firstName = first;
3 this.lastName = last;
4 this.age = age;
5 this.eyeColor = eye;
6}
1function Bird() {
2 this.name = "Albert";
3 this.color = "blue";
4 this.numLegs = 2;
5}
6/*
7This constructor defines a Bird object with properties name, color, and
8numLegs set to Albert, blue, and 2, respectively.
9Constructors follow a few conventions:
10-Constructors are defined with a capitalized name to distinguish them from
11other functions that are not constructors.
12
13-Constructors use the keyword this to set properties of the object they will
14create. Inside the constructor, this refers to the new object it will create.
15
16-Constructors define properties and behaviors instead of returning a value as
17other functions might.
18*/
1function Bird() {
2 this.name = "Albert";
3 this.color = "blue";
4 this.numLegs = 2;
5}
6
7let blueBird = new Bird();
8