How to magically get Object key?

It is possible to get hero key in the translate function?

let books = {
  hero: translate([
    'Batman',
    'Superman',
    'Ironman'
  ])
}

function translate(param1) {
  return ...
}

Maybe there is some magic how to get calling key name ? :) Thanks!

Upvotes: 4

Views: 51

Answers (1)

T.J. Crowder
T.J. Crowder

Reputation: 1074068

You're asking if a function called as part of a property initializer in an object initializer can access the name of the property its return value will be used to initialize.

No, it can't. Functions have no knowledge of how their return value will be used.

Upvotes: 4

Related Questions