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. javascript - 有没有什么办法过滤掉数据库中的乱码?2. 主从复制 - MySQL 主从延迟 300s 以上,求大神解答3. mysql - 数据库设计问题4. javascript - JS用ajax爬取百度外卖店家信息5. insert.php文件运行错误,如何解决?6. mysql - 表名称前缀到底有啥用?7. wordpress - ubuntu14.04下apache2修改根目录导致wrodpress没办法使用8. composer安装一直提示需要gmp扩展9. mysql update 出错10. mysql - PHP 批量插入的时候 判断数据表里面是否重复怎么优化

网公网安备