也許類似於How do I configure ESLint to allow fat arrow class methodsESLint示出了類實例屬性錯誤初始化爲箭頭功能
當類方法定義爲箭頭函數Eslint高亮錯誤「方法」沒有定義。 (無爲undef)。 簡單的例子
class abc {
d =() => {
// method body
}
}
這裏就不difined 'd'
我.eslintrc配置
{
"env": {
"browser": true,
"es6": true
},
"extends": [
"eslint:recommended",
"plugin:flowtype/recommended"
],
"parser": "babel-eslint",
"parserOptions": {
"ecmaFeatures": {
"experimentalObjectRestSpread": true,
"jsx": true
},
"sourceType": "module"
},
"plugins": [
"react",
"flowtype"
],
"rules": {
"indent": [
"error",
2
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"always"
]
}
}
.babelrc
{
"presets": ["react", "es2015", "stage-1", "flow"]
}
也許我需要聲明一些規則?
ES6類沒有實例變量,這就是'd'在這裏。 – 2017-08-17 03:47:07
箭頭函數在'class'中沒有意義 - 就像設置'Something.prototype.somefunction =()=> {}'沒有意義 –
@torazaburo - 'class'語法不提供實例變量,但是如果在方法中創建的話,結果類可以擁有它們。 (正在選擇措辭。)(所以我的措辭可能也是錯誤的。) – nnnnnn