Inheritance in JavaScript - #28 @Everyday-Be-Coding

preview_player
Показать описание

In JavaScript, prototypes and inheritance play crucial roles in how objects are structured and how they inherit behavior and properties from other objects. Here's a brief overview:

Prototypes:
JavaScript is a prototype-based language, meaning that objects can directly inherit properties and methods from other objects. Every JavaScript object has an internal property called [[Prototype]], which is a reference to another object. This reference forms a prototype chain.

Prototype Object: Each object in JavaScript has a prototype object from which it inherits properties.

Constructor Functions: Constructor functions are used to create objects with a shared prototype. When you create objects using a constructor function with the new keyword, the newly created object inherits properties and methods from the constructor's prototype property.

JavaScript code
function Person(name) {
}

};

var person1 = new Person("Alice");

javascript
Copy code
var personProto = {
sayHello: function() {
}
};

Inheritance:
Inheritance in JavaScript is achieved by setting up the prototype chain, where objects inherit properties and methods from their prototype objects.

Prototype Chain: When you access a property or method on an object, JavaScript first looks for it on the object itself. If it's not found, it continues up the prototype chain until it finds the property or method or reaches the end of the chain.

Inheriting from Prototypes: By setting the prototype of one constructor function to be an instance of another constructor function, you can establish inheritance.

JavaScript code:
function Animal(name) {
}

};

function Dog(name, breed) {
}

};

var myDog = new Dog("Buddy", "Labrador");
In this example, Dog inherits from Animal, and instances of Dog have access to both Animal's methods (sayName) and its own methods (bark).

JavaScript Inheritance,
Prototypal Inheritance,
Object-Oriented JavaScript,
JavaScript Class Inheritance,
JavaScript Prototype Chain,
Inheritance Patterns in JavaScript,
JavaScript Object Creation Patterns,
JavaScript Subclassing,
JavaScript Constructor Functions,
Understanding JavaScript Inheritance

Chapter :
00:00 Inro
00:19 Prototype Chain
00:45 Prototype Chain Example
01:18 Constructor Inheritance
01:42 Constructor Inheritance Example
02:01 ES6 Class Syntax
02:44 Summery

Thank you for watching this video
EVERYDAY BE CODING
Рекомендации по теме
join shbcf.ru