javascript - Is a function return value possible as an array key? -


i made lazy utility function wanted pass arrays key getting syntax errors, possible pass function inside array it's key?

function encloseattrselector(attr, value) {     return '[' + attr + '="' + value + '"]'; }    

..

example (typically more 1 pair):

var data = { encloseattrselector('name', 'username'):  row.first().text() }; 

in es6 es2015 (the newest official standard language) yes, in real-life contexts no. can this:

var data = {}; data[encloseattrselector('name', 'username')] = row.first().text(); 

the new es2015 syntax is:

var data = { [encloseattrselector('name', 'username')] : row.first().text() }; 

that is, square brackets around property name in object initializer expression. inside square brackets can expression.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -