Advertisement
ralitsa_d

Mixins

Nov 4th, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function createMixins() {
  2.     function computerQualityMixin(classToExtend) {
  3.         function attach() {
  4.             this.getQuality = function () {
  5.                 return (this.processorSpeed_Ghz + this.ram_Gb + this.hardDiskSpace_Tb) / 3;
  6.             };
  7.  
  8.             this.isFast = function () {
  9.                 return this.processorSpeed_Ghz > (this.ram_Gb / 4);
  10.             };
  11.  
  12.             this.isRoomy = function () {
  13.                 return this.hardDiskSpace_Tb > Math.floor(this.ram_Gb * this.processorSpeed_Ghz);
  14.             };
  15.         }
  16.         attach.call(classToExtend.prototype);
  17.     }
  18.  
  19.     function styleMixin(classToExtend) {
  20.         function attach() {
  21.             this.isFullSet = function () {
  22.                 return this._keyboard.manufacturer === this._monitor.manufacturer;
  23.             };
  24.  
  25.             this.isClassy = function () {
  26.                 let batteryLifeCondition = this._battery.expectedLife >= 3;
  27.                 let colorCondition = ["Silver", "Black"].includes(this.color);
  28.                 let weightConition = this.weight < 3;
  29.  
  30.                 return batteryLifeCondition && colorCondition && weightConition;
  31.             }
  32.         }
  33.  
  34.         attach.call(classToExtend.prototype);
  35.     }
  36.  
  37.     return{
  38.         computerQualityMixin,
  39.         styleMixin
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement