javascript - es6 hash array index function call mixed syntax -


what kind of es6 syntax this?

{   [actiontypes.repo](state, { username, res }) {     /* ... */   },    [actiontypes.repo2](state, { username, res }) {     /* ... */ } 

taken : https://github.com/quangbuule/redux-example/blob/master/src/js/reducers/repo.js

those method definitions, computed property names , destructuring @ work.

method definitions provide concise way create properties contain functions:

// before var obj = {   foo: function() {} };  // var obj = {    foo() {} }; 

that's same syntax creating methods in class definitions.

computed properties allow use result of expression property name in object literal:

var foo='somepropertyname';  // before var obj = {}; obj[foo] = 42;  //  var obj = {   [foo]: 42 }; 

and of course works method definitions:

var obj = {   [foo]() {} }; 

destructuring pattern matching , makes easier refer nested properties of array/object if thats need:

// before function foo(obj) {   var username = obj.username;   var res = obj.res; }  // function foo({username, res}) {  } 

Comments