javascript - js中括號問題
問題描述
import {INCREMENT} from './types'const mutations = { [INCREMENT] (state) { state.count++; }}
[INCREMENT] INCREMENT是變量直接使用不就行了嗎,為什么還要加一個中括號呢?
問題解答
回答1:[INCREMENT]是計算INCREMENT這個變量的值作為函數(shù)名,不使用中括號是把INCREMENT這個字符串作為函數(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. css3 - sublime text2 的less2css插件怎么使用2. html5 - z-index在瀏覽器調(diào)試有效 手機(jī)測試無效3. 關(guān)于docker下的nginx壓力測試4. angular.js使用$resource服務(wù)把數(shù)據(jù)存入mongodb的問題。5. angular.js - angularjs的自定義過濾器如何給文字加顏色?6. docker-machine添加一個已有的docker主機(jī)問題7. 為什么我ping不通我的docker容器呢???8. docker - 如何修改運行中容器的配置9. nignx - docker內(nèi)nginx 80端口被占用10. docker安裝后出現(xiàn)Cannot connect to the Docker daemon.
