No way to access string fields on objects
reynir opened this issue · 0 comments
reynir commented
For example it's impossible to access the 'foo/bar' field on the following object
let a = { 'foo/bar' : 42 } // It's impossible to access a['foo/bar']
In general you can't access the fields if you
- Don't know the key in advance, or
- The key isn't a valid identifier (ex. 'foo/bar')
A "workaround" is to use eval:
let a = { 'foo/bar' : 42 }
let x = eval 'a["foo/bar"]'
It's not pretty and requires that the identifiers are "stable".