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. html5 - h5寫的app用的webview,用手機瀏覽器打開不顯示?2. php - 第三方支付平臺在很短時間內多次異步通知,訂單多次確認收款3. mysql - 一個表和多個表是多對多的關系,該怎么設計4. objective-c - iPhone如何實現微信的搖一搖功能?5. mysql新建字段時 timestamp NOT NULL DEFAULT ’0000-00-00 00:00:00’ 報錯6. 我在導入模板資源時遇到無法顯示的問題,請老師解答下7. javascript - 百度echarts series數據更新問題8. Mysql && Redis 并發問題9. mysql scripts提示 /usr/bin/perl: bad interpreter10. 請教一個python字符串處理的問題?
