+ 1
use of ['mobile' + param.charAt(0).toUpperCase() + param.slice(1)]: 4
I am not able to understand the given line of code:- ['mobile' + param.charAt(0).toUpperCase() + param.slice(1)]: 4 FULL CODE:- var param = 'size'; var config = { [param]: 12, ['mobile' + param.charAt(0).toUpperCase() + param.slice(1)]: 4 }; console.log(config.mobileSize);
1 Resposta
+ 2
it's the new ES6’s “Computed Property Names” feature that allows you to have an expression (a piece of code that results in a single value like a variable or function invocation) be computed as a property name on an object.
have look at → https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer#Computed_property_names