nbb 2024-03-01

If I have a file named backup.js with the contents const data = [ { "foo": "bar" } ], what is the best way to eval and read that data without needing to modify the file?

Read the file and use Js/eval?

ok. That's about what I figured. Wanted to make sure there wasn't something else I was missing

So, it seems like doing that, I can read it if it's var data = but not const data =

$ nbb -e '(js/eval "const x = 1; x")'
1

👍 1

I was trying to do it with js/data which only worked for var but not const or let

never heard of js/data

$ nbb -e '(prn js/data)'
nil

data was the var that was defined inside the eval-ed file. I was trying to refer to it using js/ but your way works.

another way could be:

$ nbb -e '(def f (js/Function. "const x = 1; return x;")) (f)'
1

👍 1

but you still have to add something to the source