4

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!

2
  • 1
    declare your book correctly Commented Dec 16, 2017 at 14:12
  • T.J. Crowder, yes, sorry, my bad ;) Commented Dec 16, 2017 at 14:18

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.