Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Raptor {
- constructor(build) {
- if (arguments.length === 1 && this.validateBuild(build)) {
- let specimenId = build.specimenId;
- let speed = build.speed;
- let plumage = build.plumage;
- Object.defineProperties(this, {
- '_specimenId': {
- value: specimenId,
- writable: false
- },
- '_speed': {
- value: speed,
- writable: false
- },
- '_plumage': {
- value: plumage,
- writable: false
- }
- });
- }
- }
- validateBuild(build) {
- return (String(build.constructor) === String(Raptor.Builder));
- }
- static get Builder() {
- class Builder {
- constructor(specimenId) {
- this.specimenId = specimenId;
- }
- withSpeed(speed) {
- this.speed = speed;
- return this;
- }
- withPlumage(plumage) {
- this.plumage = plumage;
- return this;
- }
- build() {
- return new Raptor(this);
- }
- }
- return Builder;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement