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 - 数据库建字段,默认值空和empty string有什么区别 1102. 问一下代码哪里出错了????3. mybatis - Java关于Mysql的随机id生成4. Mac下phpinfo和php -m里的扩展不一致怎么解决?5. 求问:其它输出都正常,就是错误输出是乱码!6. python - UTC格式转换成本地时间7. angular.js - 在ionic下,利用javascript导入百度地图,pc端可以显示,移动端无法显示8. python - 如何使用requests模块在一个post中提交含有多个相同名称的数据?9. windows - Mysql数据库部署 能否不安装服务?10. 冒昧问一下,我这php代码哪里出错了???