1class Person {
2 constructor(name) {
3 this.name = name;
4 }
5 introduce() {
6 console.log(`Hello, my name is ${this.name}`);
7 }
8}
1function Person(first, last, age, eye) {
2 this.firstName = first;
3 this.lastName = last;
4 this.age = age;
5 this.eyeColor = eye;
6}
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 Bird() {
2 this.name = "Albert";
3 this.color = "blue";
4 this.numLegs = 2;
5}
6
7let blueBird = new Bird();
8
1function Tree(name) {
2 this.name = name
3}
4
5let theTree = new Tree('Redwood')
6console.log('theTree.constructor is ' + theTree.constructor)
7
1// constructor function
2function Person () {
3 this.name = 'John',
4 this.age = 23
5}
6
7// create an object
8const person = new Person();