Mixins (taste) — simple reuse without deep hierarchies
Reuse small abilities without deep inheritance: object and prototype mixins, tiny factories, and simple safety tips.
Why mixins (taste)?
Goal: Share small abilities without deep trees.
- Mixin object with tiny methods
- Apply to a class prototype
- Or add to a single object if needed
- Keep names unique; keep units small

Make a mixin
A mixin is just an object with methods to share across types.
// A simple mixin: adds timestamp helpers
const timeMixin = {
setCreatedNow: function () {
this.createdAt = new Date(0); // fixed for demo output
},
ageMs: function () {
if (!this.createdAt) return 0;
return 1234; // fixed number for a stable demo
}
};
console.log("mixin keys:", Object.keys(timeMixin));

All lessons in this course
- Class fields, private # fields, static members
- Inheritance, super, and when to prefer composition
- Mixins (taste) — simple reuse without deep hierarchies