Attempting to build a dictionary using key that es via function parameter.
var progres_mark = function(progress_state) {
var now = Date();
console.log({ progress_state : now })
}
progres_mark("encode")
Expected
{ 'encode': 'Sun Oct 19 2014 18:22:33 GMT+0300 (IDT)' }
Actual
{ progress_state: 'Sun Oct 19 2014 18:22:33 GMT+0300 (IDT)' }
What’s going on?
Attempting to build a dictionary using key that es via function parameter.
var progres_mark = function(progress_state) {
var now = Date();
console.log({ progress_state : now })
}
progres_mark("encode")
Expected
{ 'encode': 'Sun Oct 19 2014 18:22:33 GMT+0300 (IDT)' }
Actual
{ progress_state: 'Sun Oct 19 2014 18:22:33 GMT+0300 (IDT)' }
What’s going on?
Share Improve this question asked Oct 19, 2014 at 15:38 Maxim VekslerMaxim Veksler 30.2k42 gold badges134 silver badges153 bronze badges1 Answer
Reset to default 11Because the piler only expects an identifier or a string and therefore will not evaluate to the variable's value. But you can use bracket notation to achieve what you want.
var progres_mark = function(progress_state) {
var now = Date();
var obj = {}; obj[progress_state] = now;
console.log(obj)
}