Skip to content

Instantly share code, notes, and snippets.

@newbornfrontender
Created January 9, 2020 14:31
Show Gist options
  • Save newbornfrontender/28c86fac94490924ebc9c15e32900e99 to your computer and use it in GitHub Desktop.
Save newbornfrontender/28c86fac94490924ebc9c15e32900e99 to your computer and use it in GitHub Desktop.
babel class fields and pipline operator
const Point = class {
x = 0;
y = 0;
};
const serializable = Category => class extends Category {
toString() {
return `[${this.x}, ${this.y}]`;
}
};
const movable = Category => class extends Category {
move(x, y) {
this.x += x;
this.y += y;
}
};
const PointEx = Point |> serializable |> movable;
const point = new PointEx();
point.move(6, -4);
console.log(point.toString());
const { x, y } = point;
console.log(x, y);
var _temp, _ref, _Point;
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
const Point = (_temp = class Point {
constructor() {
_defineProperty(this, "x", 0);
_defineProperty(this, "y", 0);
}
}, _temp);
const serializable = Category => class extends Category {
toString() {
return `[${this.x}, ${this.y}]`;
}
};
const movable = Category => class extends Category {
move(x, y) {
this.x += x;
this.y += y;
}
};
const PointEx = (_ref = (_Point = Point, serializable(_Point)), movable(_ref));
const point = new PointEx();
point.move(6, -4);
console.log(point.toString());
const {
x,
y
} = point;
console.log(x, y);
{
"devDependencies": {
"@babel/cli": "^7.7.7",
"@babel/core": "^7.7.7",
"@babel/plugin-proposal-class-properties": "^7.7.4",
"@babel/plugin-proposal-pipeline-operator": "^7.7.7"
},
"scripts": {
"build": "babel input.js -o output.js"
},
"babel": {
"plugins": [
"@babel/proposal-class-properties",
["@babel/proposal-pipeline-operator", {
"proposal": "minimal"
}]
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment