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 - 使用angular中,圖片上傳功能中選擇多張圖片是怎么實現的?有什么好的思路嗎?2. javascript - jquery選擇的dom元素如何更新?3. .......4. python - Django問題 ’WSGIRequest’ object has no attribute ’user’5. 數據庫 - mysql boolean型無法插入true6. centos - apache配置django報錯:cannot be loaded as Python modules7. python - flask jinjia2 中怎么定義嵌套變量8. javascript - URL中有#號如何來獲取參數啊? nodejs9. MYSQL 的 SELECT 語句中如何做到判斷字段為空10. javascript - H5頁面無縫輪播
