如預期,但應該看各地的網絡示例此代碼不能編譯。ES6 Arrow功能編譯錯誤
ERROR in ./src/main/javascript/app.js
Module build failed: SyntaxError: Unexpected token (66:18)
64 | }
65 |
> 66 | addErrorAlert = (title, message) => {
| ^
67 | this.state.toastContainer.error(
68 | message,
69 | title,
所討論的方法,它實際上是延伸React.Component
一個EM6類的一部分addErrorAlert = (title, message) => {
this.state.toastContainer.error(
message,
title,
{
timeOut: 10000,
extendedTimeOut: 10000,
preventDuplicates: true,
positionClass: "toast-bottom-full-width",
showMethod: "fadeIn",
hideMethod: "fadeOut"
}
);
};
的WebPack配置
var path = require('path');
var node_dir = __dirname + '/node_modules';
module.exports = {
entry: './src/main/javascript/app.js',
devtool: 'sourcemaps',
cache: true,
debug: true,
resolve: {
alias: {
'stompjs': node_dir + '/stompjs/lib/stomp.js',
}
},
output: {
path: __dirname,
filename: './src/main/resources/static/built/bundle.js'
},
module: {
loaders: [
{
test: path.join(__dirname, '.'),
exclude: /(node_modules)/,
loader: 'babel-loader',
query: {
cacheDirectory: true,
presets: ['es2015', 'react']
}
}
]
}
};
'addErrorAlert'函數是否應該返回任何東西或者是一個動作? –
這只是一個動作,但我可能需要更新的狀態。我認爲箭頭函數是一種避免this.method = this.method.bind(this)的方法,因爲這會在一段時間後變得令人討厭 – greyfox