end video

This lesson is only accessible in the paid version of the course.

Get access to all lessons 💫 price: 34.99$

If you already have an account click here.

§ Using Mixins to Share Behavior in JavaScript

In this video, we will be diving into the concept of mixins and how they can be used to share behavior among objects.

Mixins in JavaScript are a way to extend the functionality of an object by adding properties and methods from another object, without having to inherit from it. They allow for code reuse and a more modular approach to programming. In JavaScript, mixins are typically implemented using Object.assign() or the spread operator. For example:

const Mixin = {
  log() {
    console.log(`My name is ${this.name}`);
  }
}

function User(n) {
  this.name = n;
}

Object.assign(User.prototype, Mixin);

const u = new User('Krasimir');
u.log();
questionnaire

Practice

Practice is the fastest way to learn knowledge permanently. I have prepared a small task for you related to the lesson.

Practice
discussion

Materials

Materials related to the lesson:
Files associated with the lesson

Materials

Next: Command pattern done with generators(05:39)

To the lesson →