0

I currently do:

function outer(prop_name) {
    const tmp = {};
    tmp[prop_name] = 'hello world';
    foo(tmp);
}

Is there a way of rewriting this as:

foo(<expression>) 

using an expression involving prop_name?

fadedbee
  • 42,671
  • 44
  • 178
  • 308
  • if foo is you function u can return object in outer and then do foo(outer()); – Mladen Skrbic Oct 17 '18 at 11:04
  • Yes, that is a solution to the example, but that doesn't answer the question "Is it possible to create a ES6 Javascript expression whose value is an object with a dynamic property name?". – fadedbee Oct 17 '18 at 11:15

1 Answers1

5

You can write it as

foo({ [prop_name] : 'hello_world'});

M4stah
  • 66
  • 1