相关文章推荐
大鼻子的镜子  ·  mktime (Date and ...·  1 年前    · 
打盹的酸菜鱼  ·  Malware removes ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

This is a beginner's question and the context doesn't really matter, and neither whether it makes sense at all.

I want to create class properties with dynamic names within a method of the class . Essentially something like this (the code does not work, of course):

class Trial {
    set_dynamic_property(name, value) {
        this.setAttribute(name, value)

How do I achieve this?

Thanks, this works! I thought I had tried exactly this, but I must have messed up something. – monade May 2, 2020 at 9:28

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.