Reputation: 3210
I'm trying to export the toString method alone but it's failing. The first export is working fine but the other one I added is failing.
class Point {
constructor(x, y) {
this.x = x;
this.y = y;
}
toString() {
return `(${this.x}, ${this.y}`;
}
}
export {Point as XPoint}; // this is working great
but this is failing
export {Point.prototype.toString as PointToString};
What is the proper export syntax for exporting specific method in a class?
Here is the error that webpack is saying:
ERROR in ./es6/Point.js Module build failed: SyntaxError: /Users/demouser/repos/webpack-es6-demo/es6/Point.js: Unexpected token (12:13)
Upvotes: 0
Views: 132
Reputation: 13570
You can only use identifiers inside of export specifiers:
const PointToString = Point.prototype.toString;
export { PointToString }
See: http://www.ecma-international.org/ecma-262/6.0/index.html#sec-exports
Upvotes: 1