javascript - js中括號問題
問題描述
import {INCREMENT} from './types'const mutations = { [INCREMENT] (state) { state.count++; }}
[INCREMENT] INCREMENT是變量直接使用不就行了嗎,為什么還要加一個(gè)中括號呢?
問題解答
回答1:[INCREMENT]是計(jì)算INCREMENT這個(gè)變量的值作為函數(shù)名,不使用中括號是把INCREMENT這個(gè)字符串作為函數(shù)名。
const INCREMENT = ’myfunc’;const mutations = { [INCREMENT] (state) { state.count++; }}
相當(dāng)于上面的代碼,結(jié)果是
const mutations = { myfunc(state) { state.count++; }}
而
const INCREMENT = ’myfunc’;const mutations = { INCREMENT (state) { state.count++; }}
的結(jié)果是
const mutations = { INCREMENT(state) { state.count++; }}回答2:
這是 computed property names
https://developer.mozilla.org...
相關(guān)文章:
1. 人工智能 - python 機(jī)器學(xué)習(xí) 醫(yī)療數(shù)據(jù) 怎么學(xué)2. python - oslo_config3. 請教一個(gè)mysql去重取最新記錄4. python - 請問這兩個(gè)地方是為什么呢?5. Python處理Dict生成json6. 急急急!!!求大神解答網(wǎng)站評論問題,有大神幫幫小弟嗎7. javascript - 按鈕鏈接到另一個(gè)網(wǎng)址 怎么通過百度統(tǒng)計(jì)計(jì)算按鈕的點(diǎn)擊數(shù)量8. python2.7 - python 正則前瞻 后瞻 無法匹配到正確的內(nèi)容9. 大家都用什么工具管理mysql數(shù)據(jù)庫?10. mysql - Sql union 操作
