javascript - js中括號問題
問題描述
import {INCREMENT} from './types'const mutations = { [INCREMENT] (state) { state.count++; }}
[INCREMENT] INCREMENT是變量直接使用不就行了嗎,為什么還要加一個中括號呢?
問題解答
回答1:[INCREMENT]是計算INCREMENT這個變量的值作為函數名,不使用中括號是把INCREMENT這個字符串作為函數名。
const INCREMENT = ’myfunc’;const mutations = { [INCREMENT] (state) { state.count++; }}
相當于上面的代碼,結果是
const mutations = { myfunc(state) { state.count++; }}
而
const INCREMENT = ’myfunc’;const mutations = { INCREMENT (state) { state.count++; }}
的結果是
const mutations = { INCREMENT(state) { state.count++; }}回答2:
這是 computed property names
https://developer.mozilla.org...
相關文章:
1. mysql - AttributeError: ’module’ object has no attribute ’MatchType’2. javascript - JS設置Video視頻對象的currentTime時出現了問題,IE,Edge,火狐,都可以設置,反而chrom卻...3. github - 利用Python 自動化部署問題4. 求大神幫我看看是哪里寫錯了 感謝細心解答5. objective-c - iOS怎么實現像QQ或者微信的實時推送6. 網頁爬蟲 - python爬蟲翻頁問題,請問各位大神我這段代碼怎樣翻頁,還有價格要登陸后才能看到,應該怎么解決7. python - from ..xxxx import xxxx到底是什么意思呢?8. php自學從哪里開始?9. phpstady在win10上運行10. 數據庫 - MySQL 單表500W+數據,查詢超時,如何優化呢?
