puffnfresh/roy

No way to access string fields on objects

reynir opened this issue · 0 comments

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

  1. Don't know the key in advance, or
  2. 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".