简体   繁体   中英

Python dictionaries in javascript

I didn't really know how to parse the title very well but, what I need help with is I was watching a tutorial on how to make a programming language in python. I wanted to make it in javascript. I got the lexer working but then came to the parser. In the tutorial they do this:

t = {token['value']: []}

I want to do that in javascript. But when I try to do that I can user the token['value'] part to as a 'label' so to say.

Thanks!

You may be looking for computed properties:

const t = {
  [token.value]: []
};

Then you will be able to access t[token.value] .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM