kstoyanov

06. ** Mixins

Oct 16th, 2020
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function createMixins() {
  2.     function computerQualityMixin(classToExtend) {
  3.         classToExtend.prototype.getQuality = function () {
  4.             return (this.processorSpeed + this.ram + this.hardDiskSpace) / 3;
  5.         };
  6.  
  7.         classToExtend.prototype.isFast = function () {
  8.             return this.processorSpeed > (this.ram / 4)
  9.         };
  10.  
  11.         classToExtend.prototype.isRoomy = function () {
  12.             return this.hardDiskSpace > Math.floor(this.ram * this.processorSpeed)
  13.         };
  14.     }
  15.  
  16.     function styleMixin(classToExtend) {
  17.         classToExtend.prototype.isFullSet = function () {
  18.             return this.manufacturer === this.keyboard.manufacturer &&
  19.                 this.keyboard.manufacturer === this.monitor.manufacturer
  20.         };
  21.  
  22.         classToExtend.prototype.isClassy = function () {
  23.             const isCorrectColor = this.color === "Silver" || this.color === "Black";
  24.             return this.battery.expectedLife >= 3 && isCorrectColor && this.weight < 3
  25.         }
  26.     }
  27.  
  28.     return {
  29.         computerQualityMixin,
  30.         styleMixin
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment