JavaScript Constructors Explain in 5 min | #36

preview_player
Показать описание
JavaScript Constructors Explain in 5 min | #36

Courses:

HTML:

CSS:

Other videos

► How to Make Animated Portfolio Website Using HTML CSS & JS - Light & Dark Mode Website Tutorial:

► Responsive Personal Portfolio Website using HTML & CSS - How to Make a Website:

► Animated Portfolio Website Template in HTML CSS | Animated Personal Website - Responsive Design:

► How To Make A Website Using HTML CSS Bootstrap - Real Estate Website - Bootstrap Website Design:

► Responsive Ecommerce Website:

►CSS Button Hover Effect:

►CSS Loading Animation:

►Video Background Landing Page:

►Working JavaScript Clock:

►CSS Loading Animation Effects:

Instagram:
Рекомендации по теме
Комментарии
Автор

// Constructor = special function used to create objects (make lots of objects that all share the same structure)

function Person(name, age, color) {
// Properties
this.name = name;
this.age = age;
this.color = color;

// method
this.sayHello = function () {
console.log("Hello, my name is " + this.name + " and I am " + this.age + " years old.");
}
}

// create object
const person1 = new Person("John", 25, "blue");
const person2 = new Person("Jennifer", 22, "brown");
const person3 = new Person("Sam", 28, "green");

// Accessing properties & method
person1.sayHello();


// adding new property & method to the constructor
Person.prototype.address = "Unknown Address";


Person.prototype.sayHello = function () {
console.log("Hello, my name is " + this.name + " and I am " + this.age + " years old.");
}

person3.sayHello();

webcontent