Advertisement
Guest User

Untitled

a guest
Sep 21st, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Raptor {
  2.    constructor(build) {
  3.       if (arguments.length === 1 && this.validateBuild(build)) {
  4.          let specimenId = build.specimenId;
  5.          let speed = build.speed;
  6.          let plumage = build.plumage;
  7.          Object.defineProperties(this, {
  8.             '_specimenId': {
  9.                value: specimenId,
  10.                writable: false
  11.             },
  12.             '_speed': {
  13.                value: speed,
  14.                writable: false
  15.             },
  16.             '_plumage': {
  17.                value: plumage,
  18.                writable: false
  19.             }
  20.          });
  21.       }
  22.    }
  23.    validateBuild(build) {
  24.       return (String(build.constructor) === String(Raptor.Builder));
  25.    }
  26.    static get Builder() {
  27.       class Builder {
  28.          constructor(specimenId) {
  29.             this.specimenId = specimenId;
  30.          }
  31.          withSpeed(speed) {
  32.             this.speed = speed;
  33.             return this;
  34.          }
  35.          withPlumage(plumage) {
  36.             this.plumage = plumage;
  37.             return this;
  38.          }
  39.          build() {
  40.             return new Raptor(this);
  41.          }
  42.       }
  43.       return Builder;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement