Created
January 9, 2020 14:31
-
-
Save newbornfrontender/28c86fac94490924ebc9c15e32900e99 to your computer and use it in GitHub Desktop.
babel class fields and pipline operator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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