2015-07-15 12:30:11 +08:00
|
|
|
/**
|
|
|
|
* The `mixin` utility assigns the properties of a set of 'mixin' objects to
|
|
|
|
* the prototype of a parent object.
|
|
|
|
*
|
|
|
|
* @example
|
2017-05-09 19:58:07 +08:00
|
|
|
* class MyClass extends mixin(ExistingClass, evented, etc) {}
|
2015-07-15 12:30:11 +08:00
|
|
|
*
|
|
|
|
* @param {Class} Parent The class to extend the new class from.
|
|
|
|
* @param {...Object} mixins The objects to mix in.
|
|
|
|
* @return {Class} A new class that extends Parent and contains the mixins.
|
|
|
|
*/
|
2015-04-25 20:58:39 +08:00
|
|
|
export default function mixin(Parent, ...mixins) {
|
|
|
|
class Mixed extends Parent {}
|
2015-07-15 12:30:11 +08:00
|
|
|
|
2020-04-17 17:57:55 +08:00
|
|
|
mixins.forEach((object) => {
|
2015-07-15 12:30:11 +08:00
|
|
|
Object.assign(Mixed.prototype, object);
|
|
|
|
});
|
|
|
|
|
2015-04-25 20:58:39 +08:00
|
|
|
return Mixed;
|
|
|
|
}
|